new Date(null)
// Date 1970-01-01T00:00:00.000Z
How come when I type new Date(null)
in JavaScript console I'm gettingDate 1970-01-01T00:00:00.000Z
?
Because the ECMAScript 2017 standard says so?
The end of ECMA section 20.3.1.1 claims:
The exact moment of midnight at the beginning of 01 January, 1970 UTC is represented by the value +0.
...which might make you say, "...but!, but!, I did not say +0, I said":
new Date(null)
Ok, so let's follow the standard on that one...
That Date constructor example goes to section 20.3.2.2, where item 3.b.iii there says:
3.b.iii: Else, let V be ToNumber(v).
ToNumber is a hyperlink, so follow that to section 7.1.3 where there is a number conversion table that shows:
Argument Type | Result
Null | +0
Therefore:
new Date(null)
Effectively becomes:
new Date(+0)
Which is why you ultimately get:
Date 1970-01-01T00:00:00.000Z