// Native
new Date(2010, 9, 20) === new Date(2010, 9, 21);
// => false
new Date(2010, 9, 20) === new Date(2010, 9, 20);
// => true
To compare native JavaScript dates one needs to use .getTime() or .valueOf(). The first entry above happens to be false but that is due to object equality. The other lines don't return the above result on a couple of JavaScript engines:
node v8.14.0:
> new Date(2010, 9, 20) === new Date(2010, 9, 20);
false
Chrome 70.0.3538.110:
new Date(2010, 9, 20) === new Date(2010, 9, 20);
false
Firefox 64.0:
new Date(2010, 9, 20) === new Date(2010, 9, 20);
false
I've added the missing tests for this too along with examples of using .valueOf(), .getTime() or even a mix of .valueOf() and .getTime() to compare date equality.
Native under Is Same is wrong:
To compare native JavaScript dates one needs to use
.getTime()
or.valueOf()
. The first entry above happens to be false but that is due to object equality. The other lines don't return the above result on a couple of JavaScript engines:node v8.14.0:
Chrome 70.0.3538.110:
Firefox 64.0:
I've added the missing tests for this too along with examples of using
.valueOf()
,.getTime()
or even a mix of.valueOf()
and.getTime()
to compare date equality.