why foo: { bar: 10} prints 10 when executed in chrome console | Javascript -


being familiar object literal after seeing below code guessed last line "2 + 2 + 2 = 6" when executed in chrome console, got "nan" result. didn't recognize ":" after foo in line #4 , semi colon next bar in line #5 , #6. find out why, tried "foo: { bar: 10}" , printed 10. came know syntax wrong couldn't understand why didn't throw error , instead got answer 10.

var bar = 1,      foo = {};    foo: {      bar: 2;      baz: ++bar;  };  foo.baz + foo.bar + bar;

foo: label. nothing since isn't labeling useful.

{} block. groups statements, (in example) not in significant way. (important: block, not object literal.)

bar: label. ditto foo:.

10 number.

since else nothing significant, evaluating 10 10 result.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -