First, does JavaScript have no basic Date comparision the way Python might?
In my Node.js script, I have the following lines:
console.log(Date(2012,11,10) < Date(2012, 11, 9))
console.log(Date(2012,11,10) > Date(2012, 11, 9))
However, both of these lines return false.
It appears there are tons of questions about “Date Comparison in JavaScript”.
However, for virtually all of them someone responds with their home-made solution for comparing dates, some of them quite long and/or “hacky”.
Is there really no inherent or idiomatic way to simply compare dates in JavaScript.
Do any Node libraries support it?
You need to use the
newkeywordAs Elias Van Ootegem pointed out it’s a standard to return a string if the
newkeyword is omitted:Source: 15.9.2 The Date Constructor Called as a Function