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())
(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())
相关文章推荐
- The hierarchy of the type TestTest is inconsistent。It is indirectly referenced from
- 错误 the type "xxxx" is defined in an assembly that is not refernced.You must add a reference to assem
- The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from
- The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from
- Description Resource Path Location Type Project configuration is not up-to-date with pom.xml. Run pr
- The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required
- Element type is invalid: expected a string (for built-in components) or a class/function (for compos
- iOS 打包.a错误( CodeSign error: code signing is required for product type Application in SDK iOS )
- Why String is immutable in Java ?--reference
- The hierarchy of the type BeforeInfo is inconsiste
- The method setValue(String) in the type ParamTag is not applicable for the arguments (long)
- The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files
- Deprecated: Assigning the return value of new by reference is deprecated in……解决方法
- The type java.lang.Object cannot be resolved It is indirectly referenced ...
- javascript 对象及原型继承有关的属性:constructor、prototype、isPrototypeOf、instanceof、in 、hasOwnProperty 等等
- The type java.io.ObjectInputStream cannot be resolved,it is indirectly referenced from required.clas
- 错误:The method replace(int, Fragment) in the type FragmentTransaction is not applicable for the arguments (int, MyFragment)
- Solution for issue of number/currency/date/datetime/boolean type not updating in salesforce.
- 解决报错 CodeSign error: code signing is required for product type Application in SDK iOS
- 继承“HibernateDaoSupport”后,报“The hierarchy of the type AccoutDaoImpl is inconsistent”的解决方案