If wonder why
> moment(undefined).isBefore()
true
but
> moment(null).isBefore()
false
Is there any rational explanation for this behavior?
noun In mech., a zero moment.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With