javascript - Why does new Date (null, null, null) return valid date in browser? - Stack Overflow

I have been checking date function in browser and when run new Date (null, null, null); in dev tool con

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

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

Share Improve this question edited Nov 2, 2017 at 4:30 xkeshav asked Nov 1, 2017 at 19:29 xkeshavxkeshav 54.1k47 gold badges181 silver badges251 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 3

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, +[] );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744860222a4597657.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信