While trying to fully understand the difference between equality operator and identity operator, I came across an article at MSDN that explains what they both do, in terms of their inner workings, but I still had a few doubts and decided to create a flowchart so I could have a better picture. Now my question is, is this flowchart correct? or am I missing something?
It's also my understanding that the identity operator (===) would work pretty much the same way, but without attempting to convert A and B to boolean, number or string, in the first step. Is that correct?
You can see the image here too:
Ok here is the real thing, it was a matter of principles ;)
The main difference between the == and === operator in javascript is that the == operator does the type conversion of the operands before comparison, whereas the === operator compares the values as well as the data types of the operands.
The equality operator ( == ) checks whether its two operands are equal, returning a Boolean result. Unlike the strict equality operator, it attempts to convert and compare operands that are of different types.
JavaScript provides three different value-comparison operations: === — strict equality (triple equals) == — loose equality (double equals)
The equal-to operator ( == ) returns true if both operands have the same value; otherwise, it returns false . The not-equal-to operator ( != ) returns true if the operands don't have the same value; otherwise, it returns false .
is this flowchart correct?
No. You should use the ECMAScript specification for the Abstract Equality Comparison Algorithm to create the flowchart. ToBoolean is certainly not the first step (it's not used in any step).
or am I missing something?
Yes, a lot.
It's also my understanding that the identity operator (===) would work pretty much the same way, but without attempting to convert A and B to boolean, number or string, in the first step. Is that correct?
The Strict Equality Comparison Algorithm is almost identical to the Abstract Equality Comparison Algorithm, there is a difference only if the argument Types are different, and in that case there is a precise order in which the Types are made equal before the comparison is made.
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