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?
+9
A:
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
Joey
2009-12-11 16:42:48
+1 - inequality without type coercion
Russ Cam
2009-12-11 16:44:06
+7
A:
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
CMS
2009-12-11 16:43:23
about.com?! Get outta here ;) (kidding). Here's a SO discussion: http://stackoverflow.com/questions/359494/javascript-vs-does-it-matter-which-equal-operator-i-use
Crescent Fresh
2009-12-11 16:46:07
+2
A:
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.
BalusC
2009-12-11 16:45:08