Javascript operator !==

穿精又带淫゛_ 提交于 2020-01-09 07:15:05

问题


What is the difference between the !== operator and the != operator. Does it behave similar to the === operator where it compares both value and the type?


回答1:


Yes, it's the same operator like ===, just for inequality:

!== - returns true if the two operands are not identical. This operator will not convert the operands types, and only returns false if they are the same type and value. —Wikibooks




回答2:


Yes, !== is the strict version of the != operator, no type coercion is done if the operands are of different type:

0 != ''            // false, type coercion made
0 != '0'           // false
false != '0'       // false

0 !== ''           // true, no type coercion
0 !== '0'          // true
false !== '0'      // true



回答3:


I was about to post this w3schools page, but funnily enough it didn't contain this operator!

At least, the !== is indeed the inverse of === which tests the equality of both type and value.



来源:https://stackoverflow.com/questions/1889260/javascript-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!