Open salmanarshad2000 opened 10 months ago
so, overall, your state is absolutely correct , but here is the thing, [] == ![] , for this problem, even though ![] is firstly converted to boolean, there what the author meant is both sides are converted to numbers to be primitive both sides, :: If the types of the two operands are different, JavaScript attempts to convert them to a common type :: but your state is also true
This is not entirely correct also. If you are following the specs precisely here is what happens
[] == false
. I skip the step ![]
because the right hand expression obviously first needs to be evaluated before the comparison starts[] == 0
'<empty string>' == 0
Number(string)
which in the case of an empty string leads us to 0
so now we finally end up with 0 == 0
which is trueSo the correct example for this explanation really should be
[] == ![];
[] == false;
[] == 0;
'' == 0;
0 == 0;
true;
I think the coercion to a string is an important step that shouldn't be left out because otherwise the explanation gives off the impression that empty arrays are directly coerced into 0 all the time which is simply not true.
Explanation of this example is wrong: https://github.com/denysdovhan/wtfjs#-is-equal-
This is just wrong. Strings are compared as strings, null compared to undefined is true, to-primitive might return a string instead on number and so on.
First step would be to convert
![]
tofalse
because of precedence.