This NaN is not NaN:
The program code is as follows:
Copy codeThe Code is as follows:
Var date = new Date (d );
If (! Date |! Date. getFullYear ){
Return;
}
Return S. Date. format (d, 'yyyy-mm-dd'); // The formatting function, which has nothing to do with this article.
It works normally in other browsers, but in ie, the program reports an error.
In the ie debugger, it is found that date is NaN,
If it is NaN, true will be returned for if judgment, and "" will be returned, but a strange scene has occurred,
The Code indicates that if false is returned, and the console results also indicate this:
We can see that date = NaN,! Date is false ,! NaN is true. My first response is the JS Bug in ie?
Then I did some tests.
Copy codeThe Code is as follows:
Var date = NaN;
Alert (! Date) // return true
Var date = new Date ('2014-1-1-1 ');
Alert (! Date) // return false
But I thought about it for a moment. I did the following test on the console:
This indicates that the getFullYear of date exists, so date is an object.
This also shows that date is an object rather than NaN, which is just a problem with the ie debugger.
Date. getFullYear () = "NaN
Date. getDate () = "NaN
These NaN are the real NaN
Summary:
The returned result of new Date ('date text') in ie is a special date object, which is displayed as NaN by the ie debugger, the method for returning number to its call will return NaN.