why <script> {'foo':'bar'}</script> caused Uncaught SyntaxError: Unexpected token : at chrome
and <script> {foo:'bar'}</script> just fine.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because it’s not an object literal, it’s a code block. What’s inside the brackets is not parsed as key-value pairs, it’s parsed as code.
foo: 'bar'is fine as code, asfoo:is a label and'bar'is an expression.'foo':is not ok as code as a label can’t be a string, it has to be an identifier.To make it an object literal, you have to make it an expression, like:
or: