Identically Equal and Not Identically Equal

The identically equal operator is ===. The not identically equal operator is !==.

The identically equal and not identically equal operators do not convert operands before testing for equality.

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
    
        var result1 = ("2" == 2); 
        document.writeln(result1);//true - equal because of conversion 
        var result2 = ("2" === 2); 
        document.writeln(result2);//false - not equal because different data types 

       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo

The following code uses the identically equal in an if statement

 
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
  <script type="text/javascript">
    var firstVal = 5;
    var secondVal = "5";
    if (firstVal === secondVal) {
      document.writeln("They are the same");
    } else {
      document.writeln("They are NOT the same");
    }
  </script>
</body>
</html>
  
Click to view the demo

The following code shows how to use the not identically equal operator.

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
    
        var result1 = ("5" != 5); 
        document.writeln(result1);//false - equal because of conversion 
        var result2 = ("5" !== 5); 
        document.writeln(result2);//true - not equal because different data types 

       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo

null and undefined are similar values:

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">

        var result = (null == undefined); 
        document.writeln(result);//true
       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo

null and undefined are not the same type.

 
<!DOCTYPE html>
<html>
<head>
    <title>Example</title>
    <script type="text/javascript">
    
        var result = (null === undefined); 
        document.writeln(result);//false

       
    </script>
</head>
<body>
</body>
</html>
  
Click to view the demo

Performing Equality and Identity Tests on Objects

 
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
  <script type="text/javascript">
    var myData1 = {
      name : "JavaScript",
      weather : "Good",
    };
    var myData2 = {
      name : "JavaScript",
      weather : "Good",
    };
    
    var myData3 = myData2;

    var test1 = myData1 == myData2;
    var test2 = myData2 == myData3;
    var test3 = myData1 === myData2;
    var test4 = myData2 === myData3;
    document.writeln("Test 1: " + test1 + " Test 2: " + test2);
    document.writeln("Test 3: " + test3 + " Test 4: " + test4);
  </script>
</body>
</html>
  
Click to view the demo

Performing Equality and Identity Tests on Primitives

 
<!DOCTYPE HTML>
<html>
<head>
<title>Example</title>
</head>
<body>
  <script type="text/javascript">
    var myData1 = 5;
    var myData2 = "5";
    var myData3 = myData2;
    var test1 = myData1 == myData2;
    var test2 = myData2 == myData3;
    var test3 = myData1 === myData2;
    var test4 = myData2 === myData3;
    document.writeln("Test 1: " + test1 + " Test 2: " + test2);
    document.writeln("Test 3: " + test3 + " Test 4: " + test4);
  </script>
</body>
</html>
  
Click to view the demo
Home 
  JavaScript Book 
    Language Basics  

Operators:
  1. JavaScript Operators
  2. Increment/Decrement Operators
  3. Increment/Decrement Operators for String, Boolean, Floating-point and Object
  4. Unary Plus and Minus
  5. Bitwise Not operator
  6. Bitwise AND
  7. Bitwise OR
  8. Bitwise XOR
  9. Left Shift
  10. Signed Right Shift
  11. Unsigned Right Shift
  12. Logical NOT
  13. Logical AND
  14. Logical OR
  15. Multiply
  16. Divide
  17. Modulus
  18. Add
  19. Subtract
  20. Relational Operators
  21. Equal and Not Equal
  22. Identically Equal and Not Identically Equal
  23. Conditional Operator
  24. Assignment Operators
  25. Comma Operator