您的位置:首页 > Web前端 > JavaScript

Date is a reference type in JavaScript

2005-12-11 11:14 363 查看
If you try this:

(new Date(2000, 0, 1)) == (new Date(2000, 0, 1))

you may be surprised to learn that it is actually false, because they are different object references, even if the values are the same. If you want to check equality of two dates, you need to compare the values instead of the Date objects:

(new Date(2000, 0, 1)).valueOf() == (new Date(2000, 0, 1).valueOf())
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐