On the other hand, the "===" (triple equals) operator is called the "strict equality" or "strict comparison" operator. It compares the values on both sides without performing type conversion. It checks both the values and the types of the compared expressions. For the comparison to return true, both the values and types must be identical. For example, the string "2" and the number 2 would be considered not equal when using the "===" operator because they have different types.
Here are a few examples to illustrate the difference:
console.log(2 == "2"); // true (type conversion is performed) console.log(2 === "2"); // false (different types) console.log(true == 1); // true (type conversion is performed) console.log(true === 1); // false (different types)
Here's a table summarizing the differences between the two operators:
|==||Equality operator with type coercion||5 == "5" returns true|
|===||Strict equality operator without type coercion||5 === "5" returns false|
I hope you found the above information helpful. Please let me know in the comment box if you have an alternate answer 🔥 and you can support me by buying me a coffee.
And don’t forget to sign up to our email newsletter so you can get useful content like this sent right to your inbox!