JavaScript中equality(==)怎么用-创新互联

这篇文章主要介绍了JavaScript中equality(==)怎么用,具有一定借鉴价值,需要的朋友可以参考下。希望大家阅读完这篇文章后大有收获。下面让小编带着大家一起了解一下。

霸州网站制作公司哪家好,找创新互联建站!从网页设计、网站建设、微信开发、APP开发、成都响应式网站建设等网站项目制作,到程序开发,运营维护。创新互联建站成立于2013年到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联建站

神奇之处在哪里

最近负责的项目有涉及到前端的,所以尝试性的写了写js。在处理一个字段非空值的时候,用了 tagert_value == ''来进行判断,然后发生了一件非常奇怪的事情,有用户反馈,自己的target_value = 0的时候,非空值校验不通过。在调试问题的时候,在console状态栏中做了如下尝试:

> 0 == ''
< true

我似乎知道问题出在哪里了。。。没有了解清楚 == 的判断逻辑,所以我打算找来官方的文档瞅瞅。

官方解释

Equality (==, !=)

1、If the types of the two expressions are different, attempt to convert them to string, number, or Boolean.

2、NaN is not equal to anything including itself.

3、Negative zero equals positive zero.

4、null equals both null and undefined.

5、Values are considered equal if they are identical strings, numerically equivalent numbers, the same object, identical Boolean values, or (if different types) they can be coerced into one of these situations.

6、Every other comparison is considered unequal.


本文题目:JavaScript中equality(==)怎么用-创新互联
标题路径:http://myzitong.com/article/deesgi.html