Loading ...
Sorry, an error occurred while loading the content.

new Date(NaN)

Expand Messages
  • Douglas Crockford
    I had always assumed that new Date(NaN) in JavaScript would throw an exception. I found out today that produces a toxic date object, and that different
    Message 1 of 1 , Jun 18, 2009
    • 0 Attachment
      I had always assumed that new Date(NaN) in JavaScript would throw an exception. I found out today that produces a toxic date object, and that different implementations of JSON.stringify([new Date()]) do different things.

      json2.js
      ["NaN-NaN-NaNTNaN:NaN:NaNZ"]

      IE8
      ["--T::Z"]

      FireFox
      ["Invalid Date"]


      We will be correcting the ES5 standard to emit null in this case.
      The 2009-06-18 edition of json2.js contains the change.

      [null]

      Thanks to Joel Finch for the heads up.
    Your message has been successfully submitted and would be delivered to recipients shortly.