Home » Difference Between == vs === in JavaScript

Difference Between == vs === in JavaScript

Last updated on June 5, 2020 by

In this article, We will show you the difference between == vs === in JavaScript. Both == and === are used for the comparison. Let’s see how both are different.

== vs === in JavaScript

== (Double Equals)=== (Triple Equals)
It is used to compare the variables or valuesIt is also used to compare the variables/values
Doble equals do not check the data type of variable/value while the comparisonTriple Equals checks the data type of a variable while the comparison
Use this when you are unsure about the data type of variable/valuesUse this when you sure about the data type of variable/values and want strict comparison.
'1' == 1 This will return true because double equals don’t check the data type.'1' === 1 This will return false because triple equals compare the data type too. Simply string is not a number
0 == false It will return true because double equals convert the 0 to false and then compared0 === false It will return false because they are of a different type
7 == "7" // true7 === "7" // false
7 == 7 // true7 === 7 // true

That’s it for now. We hope this article helped you to learn the difference between == vs === in JavaScript.

Please let us know in the comments if everything worked as expected, your issues, or any questions. If you think this article saved your time & money, please do comment, share, like & subscribe. Thank you in advance 🙂. Keep Smiling! Happy Coding!

 
 

Leave a Comment