var moment = require('moment')
a = moment("2017-05-16")
b = moment("2017-05-17")
c = moment("2017-05-17")
We should always use moment(a).isBefore(b)
instead of a < b
. Not because the latter does not
work (both forms work!); but rather, we might be tempted to assume something like a == b
or a === b
behaves similarly.
The following operators do not work on objects and first coerce their arguments to primitives using
their arguments' valueOf
functions.
+ - * / % & | ^ << >> >>> < <= > >=
Conveniently, moment#valueOf()
returns a unix timestamp (as a Number
). Notice however == ===
are absent
from the list above. When comparing objects, the valueOf
function is always ignored. Instead the object reference
will be directly compared.
b < c // false
c < b // false
b == c // false
b === c // false