Javascript – difference between isValid() and _isValid in moment.js

html, javascript, momentjs

I want to check whether moment object is valid or not, so i used both isValid() and _isValid in different places. Both are giving same results. So i want to know purpose of using both.

Note: I know basic diff that one is function and other one is attribute.

Best Solution

isValid() is documented and so using it in prodution code is fine. It tells you whether the Moment instance contains a valid date/time.

_isValid is not documented and so using it in production code is a bad idea. It doesn't officially tell you anything. Its meaning could change, or it could disappear entirely, from one Moment to the next (see what I did there? ;-) ).

In general, in JavaScript, when you see a property name prefixed with _ it means "this is internal, pretend you don't see it."