Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  68] [ 5]  / answers: 1 / hits: 25024  / 9 Years ago, wed, october 7, 2015, 12:00:00

I wonder why


> moment(undefined).isBefore()
true

but


> moment(null).isBefore()
false

Is there any rational explanation for this behavior?


More From » date

 Answers
2

moment(undefined) is equivalent to moment(), which assumes the initial state to be the current date/time.



moment(null), on the other hand, is not a thing. It is not valid (at least not in the version I'm playing with), and has undocumented results.



Of course, you can read the source code, and find that isBefore doesn't check for undefined either. In other words, momentjs is not expecting itself to be used this way, twice.


[#64804] Monday, October 5, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
laytonlamontm

Total Points: 745
Total Questions: 130
Total Answers: 130

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
;