Difference Between equal to(==) Strict equal to(===) in JavaScript?



In this Post I am going to explain the difference between equal to(==) Strict equal to(===) in JavaScript and how they are different from each other? and why do we use them?

You might not have seen Strict equal to(===) any where. They are mostly used in if statements. Now the question is why these Strict equal to(===) are used and how they are different from normal equal to(==) ?

Equal to(==):
These are very normally used and I am sure you must have used this in if statements. Equal to(==) compares two values to see weather they same. Can be used to compare numbers or strings e.g. lets suppose we have two variables

var a=5 & var b="5"
if(a==b){
  alert("true");
}else{
  alert("false");
}

in this case we will see true in the alert box.

Strict equal to(===):
Strict equal to(===) not only compares variable’s value it compares variable type which mean to satisfy Strict equal to(===) variable should have same value as well as same variable type e.g. lets again take our previous example we have two variables

var a=5 & var b="5"
if(a===b){
  alert("true");
}else{
  alert("false");
}

in this case we will see false in the alert box because the value of both variable are same but they both are of different type var a is a number while variable b is string and to satisfy Strict equal to(===) they both should have same data type and same value

Stay tuned for the PHP Magento, WordPress, JavaScript and Magento2 latest tutorial and updates, Hope you enjoyed reading, if you need the professional Magento Development / PHP we can help you, just Click on the Link and send me your requirements.

Please Like the Post on Facebook or Google+.