I why does the console in Chrome and Firefox evaluate the current to 1
:
> {a:1}
1
I would guess that it would be evaluated as an object like if you assign it to a variable:
> var a = {a:1}
undefined
> a
Object {a: 1}
And with quotes it throws an syntax error:
> {"a":1}
SyntaxError: Unexpected token :
Try ({a:1})
.
Just executing {a:1}
is not what you think it is. It is not an object literal, which must be an expression (for example, on the right side of assignment).
Instead, what you have is a block, a label, and then a 1.
{
a:
1
}
Blocks return the result of their evaluation, and labels return the result of evaluating the statement that follows the label, so 1
is returned.
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