I know there are similar questions to this on SO, but none of them provide the answer I am looking for.
In JavaScript, if you do the following, the result will be false:
I know it is to do with how JavaScript is defined in the spec, but why is it like that? It is counter-intuitive.
If ("string" === "string")
results in being true
, then why doesn't ({ } === { })
result in being true?
I saw somewhere that the equality algorithm was designed to be similar to that of C++ or C#, but that's like inventing a brand new engine that uses 1/10th of the fuel and not using it purely for consistency with other cars.
Why was JavaScript defined in this way? Is there a reason behind this decision? Or was it just so it was seen doing the done thing?