Javascript strict equality operator

Javascript strict equality operator

Javascript provides strict equality operator to compare values and overcome the limitations of equality operator. It is denoted by triple equal ===

It returns true if the result of comparision is true, othewise it returns false.

Please note, this is not the same as assignment or simple assignment operator

This performs strict comparisions. Thus, it will not return true in cases such as 5= '5' or 5 = "5" as they are different data types. It will return false value when the types are different.

Look at the example to understand this. We are using a simple function:checkStrictEquality that accepts two parameters a, and b to test the logic.

<!DOCTYPE html>

<button onclick="checkStrictEquality(5,5)">Check if 5 = 5</button>
<button onclick="checkStrictEquality(5,2)">Check if 5 = 2</button>
<button onclick="checkStrictEquality(5,'5')">Check if 5= '5'</button>
<button onclick='checkStrictEquality(5,"5")'>Check if 5 = "5"</button>
<p id="result"></p>

function checkStrictEquality(num1num2) {
    if(num1 === num2){
        document.getElementById("result").innerHTML = "Equal";
        document.getElementById("result").innerHTML = "Not equal";


Post a Comment