Question

Why doesen't javscript just use the strict equality operator instead of both the abstract and strict equality operators?

I asked on IRC and someone commented about Microsoft didn't want to allow the functionality of "===" to go into "==" because it would break websites. No one was able to come up with any references on this though. Shortly after another person doubted the Microsoft blame as well.

Could anyone provide information on why it came to be this way with references?

Was it helpful?

Solution

JavaScript uses type coercion to automatically convert between different types of values. Sometimes, though, one wants to distinguish between "1" and 1, or between 1 and true. That's the fundamental difference between == and === (and between != and !==). Without that distinction (if, say, === was removed), one would have to jump through hoops to test type-and-value equality (and similarly with type-independent-value testing if the functionality of == were removed).

I hadn't heard about the Microsoft story. I suspect that it is bogus and would chalk it up to a tendency on the part of some people to blame Microsoft for every perceived evil. However, I would be very surprised if Microsoft, Mozilla, Google, Yahoo, almost any experienced JS programmer, etc. would be okay with the merger of == and ===. It would indeed break a huge amount of code and would remove a very useful tool from the language.

OTHER TIPS

I believe it's because they want to allow for some forms of implicit type conversion. I think the problem really comes from the fact that the rules (while well-intentioned and not too harmful individually) become monstrous when combined or in one of the "gotcha" cases typically mentioned in posts slamming "==". I personally like that there is an option, though not knowing it exists could be dangerous.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top