why foo: { bar: 10} prints 10 when executed in chrome console | Javascript [closed]

foo: is a label. It does nothing since it isn’t labeling anything useful.

{} is a block. It groups some statements, but (in this example) not in a significant way. (Important: It is a block, not an object literal.)

bar: is another label. Ditto for foo:.

10 is a Number.

Since everything else does nothing significant, you are basically evaluating 10 so you get 10 as the result.

Leave a Comment