Skip to content

JavaScript not equal | Operator

  • by

JavaScript Not equal Operator (!= & !==)is a comparison operator used to check the value of two operands is equal or not. It returns true if the value of two operands is not equal.

x !== y

The strict inequality operator (!==) checks whether its two operands are not equal, returning a Boolean result..

x != y

The inequality operator (!=) checks whether its two operands are not equal, returning a Boolean result

JavaScript not equal

A simple example code uses the not-equal operator in the If statement’s condition.

<!DOCTYPE html>
<html lang="en">
<body>
  <script>
    var x = 'apple';
    var y = 'banana';
    if (x != y) {
      console.log('x and y are not equal.');
    } else {
      console.log( 'x and y are equal.');
    }
  </script>
</body>
</html>

Output:

JavaScript not equal Operator

Inequality operator examples

console.log(1 != 1); // false

console.log('hello' != 'hello'); // false

console.log('1' !=  1); // false

console.log(0 != false); // false

Strict inequality operator examples

console.log(1 !== 1); // false

console.log('hello' !== 'hello'); // false

console.log('1' !==  1); // true

console.log(0 !== false); // true

Some Comparison Operators:

  • Equal to (==) – Check if two values are equal.
  • Strict equal to (===) – Checks are two values that are equal and of similar type.
  • Greater than (>) – Checks if the value on the left is greater than the value on the right.
  • Greater than or equal to (>=) – Checks if the value is greater than or equal to the value on the right.
  • Less than (<) – Checks if the value on the left is less than the value on the right.
  • Less than or equal to (<=) – Checks if the value is less than or equal to the value on the right

Do comment if you have any doubts or suggestions on this Js operator.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *