Javascript operator !==

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?


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


是, !==!=运算符的严格版本,如果操作数的类型不同,则不会执行类型强制:

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

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

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.

链接地址: http://www.djcxy.com/p/19380.html

上一篇: 阻止BACKSPACE返回jQuery(与Google主页一样)

下一篇: Javascript运算符!==