Your comparison is returning false because date1
and date2
are simply references to different objects, and you are actually comparing these references.
To do a proper comparison of the date values, you can use the getTime() method as follows:
date1.getTime() === date2.getTime(); // returns true