What is the difference between the !==
operator and the !=
operator in JavaScript? Does it behave similarly to the ===
operator where it compares both value and type?
Asked
Active
Viewed 1.9k times
29

double-beep
- 5,031
- 17
- 33
- 41

7wp
- 12,505
- 20
- 77
- 103
-
1Inverse of your question: http://stackoverflow.com/questions/359494/javascript-vs-does-it-matter-which-equal-operator-i-use – Crescent Fresh Dec 11 '09 at 16:44
-
Also at *[In JavaScript, is '!=' the same as '!=='?](https://stackoverflow.com/questions/1946063/)*. More answers, but this is the duplicate target. – Peter Mortensen Sep 02 '22 at 21:13
3 Answers
37
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
- 344,408
- 85
- 689
- 683
-
I really think the correct answer needs the word coercion somewhere in it. Converting also makes sense but to be succinct it should be made clear that it's an implicit conversion happening. – Alex W Oct 09 '15 at 14:06
11
Yes, !==
is the strict version of the !=
operator, and 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

Peter Mortensen
- 30,738
- 21
- 105
- 131

Christian C. Salvadó
- 807,428
- 183
- 922
- 838
6
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.

Peter Mortensen
- 30,738
- 21
- 105
- 131

BalusC
- 1,082,665
- 372
- 3,610
- 3,555