sách gpt4 ai đã đi

Tại sao new Date(null, null, null) lại trả về một ngày hợp lệ trong trình duyệt?

In lại 作者:行者123 更新时间:2023-12-03 03:08:23 31 4
mua khóa gpt4 Nike

我一直在检查浏览器中的日期函数以及运行时间

new Date (null, null, null); 在开发工具控制台中,它给出了有效的日期

Chrome v 61 回归

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

Firefox DeveloperEdition v 56 回归

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

为什么会这样?

P.S.:还尝试了 new Date(0,0,0)new Date([],[],[]),其行为也与以上并输出有效日期。

所以 null 在 Date 对象中使用时会被视为 0?

请有人解释一下这种行为并提供链接以了解这种行为

1 Câu trả lời

theolatest drafts of the specs on Date(year, month [ , date ...) ] constructor ,当

  • 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 ...

并且ToNumber(您传递的所有值)trở lại0Đúng.

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

关于javascript - 为什么 new Date(null, null, null) 在浏览器中返回有效日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47062308/

31 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com