In various programming languages there is always an operator for comparing 2 expressions, and that is the
== operator or "is equal to". This operator compares two expression and returns a boolean.
1 == 1 - This will return true
1 == 2 - This will return false.
So what's the difference between the two?
TL;DR - the other one is much stricter than its counterpart. LOL.
Loose equality is the equality operator that checks if the expressions are equal in value, but in doesn't check if they have equal data types. This can be useful if you are comparing 2 expressions that you are sure has the same data type, e.g. they are both
1 == 1 // true 1 == '1' // true - notice that the other expression is a string 1 == 2 // false 'one' == 'one' // true 'one' == 'two' // false
However, this can be confusing if the 2 expressions have the same value but different data type.
1 == '1' will return
true. It doesn't make sense right? That's why it's safer to use strict equality operator.
1 === 1 // true 1 === '1' // false - there you go 1 === 'one' // false - of course!
In conclusion, always use the strict equality, it's recommended by most linters out there anyways, so the chance of you stumbling upon companies or teams who still uses loose equality operator much lesser than those who don't.