
Can anyone describe the picture above? It is the screenshot of my Chrome dev-tool console.
Because of JavaScript coercion.
[] is loosely equated to "" and thus coerced to string using [].toString() which is equal to "".
And why does [] == [] and [] === [] return false:
the == and === comparison rules if you’re comparing two non-primitive values, like objects (including function and array). Because those values are actually held by reference, both == and === comparisons will simply check whether the references match, not anything about the underlying values.
var a = [1,2,3];
var b = [1,2,3];
var c = "1,2,3";
a == c; // true
b == c; // true
a == b; // false
arrays are by default coerced to strings by simply joining all the values with commas (,) in between.
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