Compare The Equality Of Two Date Objects
Equality can always feel like a bit of a moving target in JavaScript. Comparing two objects, even if visually/conceptually identical, will resolve to being not equal.
To compare two Date
objects, you first need to convert them to something we can check for equality -- numbers. This can be done with getTime()
.
With Date
objects, you can directly use <
, >
, <=
, and >=
.
Last updated