The Wayback Machine - https://web.archive.org/web/20211126164330/https://www.geeksforgeeks.org/difference-between-and-operator-in-javascript-2/
Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Difference between != and !== operator in JavaScript

  • Last Updated : 07 Aug, 2019
  • != 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:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!




<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>

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :