According to the ECMA script standard, the following code should return true, but it is not:
d = new Date() ; d.setTime(1436497200000) ; alert( d == 1436497200000 ) ;
Section 11.9.3 says:
- If Type (x) is either String or Number and Type (y) is Object, return the result of the comparison x == ToPrimitive (y).
Then, in section 8.12.8 , ToPrimitive readjusts the result of the valueOf method. This means that the last line in my example above should be equivalent:
alert( d.valueOf() == 1436497200000 );
Which really returns true .
Why does the first case not return true ?
javascript comparison date-comparison
Getfree
source share