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.7k times
26
![](../../users/profiles/10607772.webp)
double-beep
- 3,889
- 12
- 24
- 35
![](../../users/profiles/66803.webp)
7wp
- 12,082
- 18
- 68
- 98
-
Inverse 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
3 Answers
35
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
![](../../users/profiles/73070.webp)
Joey
- 316,376
- 76
- 642
- 652
-
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
10
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
![](../../users/profiles/74449.webp)
Myster
- 16,407
- 13
- 60
- 86
![](../../users/profiles/5445.webp)
Christian C. Salvadó
- 723,813
- 173
- 899
- 828
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.
![](../../users/profiles/157882.webp)
BalusC
- 992,635
- 352
- 3,478
- 3,452