Home » Difference Between == vs === In JavaScript

Difference Between == vs === In JavaScript

Last updated on December 24, 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.

Additionally, read our guide:

  1. jQuery Form Submit With Examples
  2. Check If Array Is Empty Or Undefined In JavaScript
  3. How To Detect IE Browser In JavaScript
  4. AJAX PHP Post Request With Example
  5. How To Declare A Global Variable in Vue
  6. How To Remove A Specific Item From An Array In JavaScript
  7. How To Check Array Contains A Value In JavaScript
  8. How To Merge Objects In Vue

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