1
votes

I have been checking date function in browser and when run

new Date (null, null, null); in dev tool console, it gives valid Date

chrome v 61 return

Sun Dec 31 1899 00:00:00 GMT+0530 (IST)

and firefox DeveloperEdition v 56 return

Date 1899-12-30T18:30:00.000Z

why so?

P.S.: also tried new Date(0,0,0) and new Date([],[],[]) and it also behave the same as above and output valid date.

so null is considered as 0 when used in Date object?

someone please explain the behaviour and link to understand this behaviour

1

1 Answers

2
votes

According to latest drafts of the specs on Date(year, month [ , date ...) ] constructor, when

  • 2 - assert numberOfArgs ≥ 2
    [...]
  • 4
    • a - Let y be ? ToNumber(year).
    • b - Let m be ? ToNumber(month).
    • c - If date is present, let dt be ? ToNumber(date); else let dt be 1 ...

And ToNumber(all the values you passed) return 0 yes.

console.log( +null, +0, +[] );