Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

{"a" : 1 } at Chrome cause SyntaxError

I met a problem at chrome. Is there some bug in chrome?

Why it cause a syntaxError? I have tried it in nodejs, it is ok.

like image 372
littlekfc Avatar asked May 29 '26 04:05

littlekfc


1 Answers

In the context in which you are running (and the Chrome and Node REPLs have different default contexts) it, the { character starts a block, not an object literal.

You can't follow a string with a : in a block.

If you were to say ({ "a": 1 }) you would change the context so it would be an object literal.

like image 200
Quentin Avatar answered May 31 '26 16:05

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!