Difference Between == and === in JavaScript with example

                                                        

   On - 8 Feb, 2023
   By - Apu Gorai
The main difference between the double equals (==) and triple equals (===) operators in JavaScript is that the triple equals operator checks for strict equality, meaning both the type and value of the compared elements must match for the operator to return true.
For example, if you wanted to check if the variable x was equal to the number 10, you would use the == operator like this - 
<script>
  let x = 10;
  x == 10 // true
</script>
However, if you wanted to check that x was of the type number and its value was 10, you would use the === operator like this:
<script>
  let x = 10;
    x === 10 // true
</script>

----[ 1 ]----

The double equals (==) operator checks for value equality, while the triple equals (===) operator checks for both type and value equality.

----[ 2 ]----

The double equals operator will attempt to convert the compared elements to the same type before checking for equality, while the triple equals operator will not.

----[ 3 ]----

The !== operator can be used to check for strict inequality, meaning that either the type or the value of the compared elements must not match for it to return true.

----[ Example ]----

<script>
  let x = 10;
  let y = "5";
   x == 10 // true
   x === 10 // true

   y == 5  // true
   y === 5 // false

   x !== 10 // false
   
   y != 5 // false
   y !== 5 // true
</script>
Read More