When checking for a String value I use '=='. But I have seen instances where '===' is used. For example, instead of
if("true" == "true"){
alert('true');
}
this is used :
if("true" === "true"){
alert('true');
}
What is the reasoning behind this ? Both use cases seem to work as expected.
The ===
operator ensures that not only the values are equal, but the two items being compared are of the same type too; Whereas the ==
operator only checks that the values of the two items are equal
As @amnotiam mentioned in the comments, you may also want to check out the The Abstract Equality Comparison Algorithm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With