This nan is not nan:
The program code is as follows:
Copy Code code as follows:
var date =new date (d);
if (!date | |!date.getfullyear) {
Return
}
Return S.date.format (d, ' yyyy-mm-dd ');//Format function, not related to this article
Normal in other browsers, but under IE, the program complains
Under the IE debugger, the date is found as Nan, as shown in figure:
If it is Nan, then if the If judgment returns True, return "", but the weird scene happens,
The code shows that if judgment returns false, the console results also illustrate this point:
You can see date = NaN, but! Date is false,! NaN is true, my first reaction, ie under JS bug?
And then I did some tests.
Copy Code code as follows:
var date = NaN;
Alert (!date)//return True
var date = new Date (' 2011-1-1 ');
Alert (!date)//return False
But I thought about it or not, and I did the following test on the console:
The getfullyear of the date is present, so date is an object
This also shows that date is an object rather than NaN, just a problem with the IE debugger
Date.getfullyear () = "NaN
Date.getdate () = "NaN
These nan are the real Nan
Summarize:
The result returned by IE under new Date (' Date text ') is a special date object, except that the IE debugger displays it as Nan, and the method that returns number on its call will return Nan.