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, +[] );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744860222a4597657.html
评论列表(0条)