Why there is ( ===) operator?


#1

Why they are telling us to use the (===) operator? even if we have (==) and both are working same.?


#2

for which language? I assume JS. They do absolutely not work the same, and its generally advised to use triple equal sign unless you have a really good reason to use double equal sign.

== doesn’t check that the data type is also a match, so "0" == 0 is true while "0" === 0 is false. But it can be far worse:

if( [] == false ){
    console.log(true);
}

but it gets worse, because 0 == "0" is true, and 0 == [] is true, so then surely "0" == [] should also be true, and that is where you would be wrong, "0" == [] is false, this is why we use triple equal sign, to avoid this weird and confusing behavior.


#3

JS doesn’t check, it coerces being as it is so bent on getting anything to work before it gives up.