admin管理员组文章数量:1130349
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 01 Answer
Reset to default 3According 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, +[] );
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 01 Answer
Reset to default 3According 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, +[] );
本文标签:
版权声明:本文标题:javascript - Why does new Date (null, null, null) return valid date in browser? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1744860219a2120833.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论