In this post I’m going to show you the difference between == and === in JavaScript.
Example:
10 == 10;
That would evaluate to true because the == compares the two values and checks whether they’re equal to each other.
Here’s another example:
10 == ’10’;
That would evaluate to true eventhough it’s comparing a number with the string ’10’ as it’s within quotes. This is because JavaScript will automatically convert one of them to make them the same data type. Once it’s done that then the statement would evaluate to true.
10 === ’10’;
In this example, however, === compares the two and checks if they’re strictly equal to each other. In this case, no such type conversions will take place. As such, a number is being compared to a string, thus the statement will evaluate to false.
Any further questions feel free to post them in the comments.
