Question

The IE9 debugger (F12 developer tools -> script debugger) shows the following in the Locals window when I step through the code when the page is launched from the server:

 midnight  Fri Mar 15 00:00:00 EDT 2013      Object, (Date) 
 myDate    Fri Mar 15 00:00:00 EDT 2013      Object, (Date)  

and yet the following conditional test for equality of value resolves to false:

 if (midnight.valueOf() === myDate.valueOf() ) {
    // these lines of code are never reached
     .
     .
     .
 }

The odd thing, the === test resolves to true on my development PC. I cannot figure out why it resolves to false on the page served up by the server. The debugger clearly indicates it should resolve to true.

The document is in "IE9 Standards" mode.

Was it helpful?

Solution

The valueOf method returns the primitive value of a Date object as a number data type, the number of milliseconds since midnight 01 January, 1970 UTC.

The debugger only shows you the seconds so the variables may actually be different.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top