Difference between != and !== operator in JavaScript
- != operator
- The inequality operator (!=) is the logical opposite of the equality operator. It means “Not Equal” and returns true where equality would return false and vice versa.
- Like the equality operator, the inequality operator will convert data types of values while comparing.
- For example 1 != ‘1’ will return false since data type conversion take place so 1 and ‘1’ are considered equal.
- !== operator
- The strict inequality operator (!==) is the logical opposite of the strict equality operator. It means “Strictly Not Equal” and returns true where strict equality would return false and vice versa.
- Strict inequality will not convert data types.
- For example 1 !== ‘1’ will return true since 1 is an integer and ‘1’ is a character and no data type conversion take place.
Example:
<script> function NotEqual(val) { if (val != 1) { return "Both are Not Equal i.e. condition is true"; } else { return "Both are Equal i.e. condition is false"; } } function StrictlyNotEqual(val) { if (val !== 1) { return "Both are Not Equal i.e. condition is true"; } else { return "Both are Equal i.e. condition is false"; } } //Passing integer console.log(" 1 != 1 " + NotEqual(1)); console.log(" 1 !== 1 " + StrictlyNotEqual(1)); //Passing character console.log(" '1' != 1 " + NotEqual('1')); console.log(" '1' !== 1 " + StrictlyNotEqual('1')); //Passing string console.log(" \"1\" != 1 " + NotEqual("1")); console.log(" \"1\" !== 1 " + StrictlyNotEqual("1")); //Passing false value i.e. 0 console.log(" 0 != 1 " + NotEqual(0)); console.log(" 0 !== 1 " + StrictlyNotEqual(0)); </script> |
chevron_right
filter_none
Output:

Recommended Posts:
- Difference between == and === operator in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- What is the difference between the | and || or operator in php?
- What is the !! (not not) operator in JavaScript?
- JavaScript | ‘===’ vs ‘==’Comparison Operator
- Arrow operator in ES6 of JavaScript
- Instanceof operator in JavaScript
- JavaScript | typeof operator
- JavaScript | Spread Operator
- How to get negative result using modulo operator in JavaScript ?
- Ternary operator / Question mark and colon in JavaScript
- Difference between JavaScript and Php
- Difference between var and let in JavaScript
- Difference between TypeScript and JavaScript
- Difference between Java and JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



