DEV Community

Cover image for The difference between lose equality and strict quality in Javascript

The difference between lose equality and strict quality in Javascript

In JavaScript, the qual value operator (==) is used to check whether a variable is equal to a value or not. Example
let p = "20";
if (p ==20){
alert("yes");
}
Looking at this code, p is actually qual to 20.
But if the if statement is like this
if (p === 20) it won't alert yes why?
Because, our strict equality or qual type and qual value operator also checks whether the values are of the same data types or not. Our "20" is a number string but what we passed in our logic is just a number.

Strict equality is really helpful, it helps you to avoid unnecessary bugs in your Codes. You can use lose quality but you have to be care on the data types.

Top comments (0)