Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moment of undefined vs moment of null

If wonder why

> moment(undefined).isBefore()
true

but

> moment(null).isBefore()
false

Is there any rational explanation for this behavior?

like image 499
rishat Avatar asked Oct 07 '15 21:10

rishat


People also ask

What is a null moment?

noun In mech., a zero moment.

Should you still use Momentjs?

Moment. js is a fantastic time & date library with lots of great features and utilities. However, if you are working on a performance sensitive web application, it might cause a huge performance overhead because of its complex APIs and large bundle size.

What will moment () return?

Displaying Formatted Dates Moment. js helps display date with specified formats. moment() returns a date and format() converts the date string tokens and replaces them with specified format values, which are readable.


1 Answers

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.

like image 77
Brian Avatar answered Sep 22 '22 12:09

Brian