On my free time, I was just playing with js console, I got an unexpected error:
js> [] == {}
false
js> {} == []
typein:5: SyntaxError: syntax error:
I tried with ===
:
js> [] === {}
false
js> {} === []
typein:9: SyntaxError: syntax error:
Am thinking wrong here?
I tested this with Firefox, Chrome and jscore.
So, what is the meaning of {} in JavaScript? In JavaScript, we use {} braces for creating an empty object. You can think of this as the basis for other object types. Object provides the last link in the prototype chain that can be used by all other objects, such as an Array.
Object.is() method is used to determine whether two values are the same or not. Two values can be same if they hold one of the following properties: If both the values are undefined. If both the values are null.
That's because in the second case, {}
is interpreted as a code block, rather than an object.
If you try ({}) == []
it works just fine.
js> ({}) == []
false
js> ({}) === []
false
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