I’ve used FireBug to test the two cases and they seem pretty similar by result:
>>> var x = {"active": "yes"}
>>> x.active
"yes"
>>> var x = {active: "yes"}
>>> x.active
"yes"
But I’m pretty sure there is some difference between these two, maybe even performance related difference. Bottom line – I’d like to know if there is a difference between {active: “yes”} and {“active”: “yes”}.
Both are valid. However there are certain keywords you cant use like
deleteso in order to avoid that you wrap them in quotes so they are not treated literally by the ECMAScript parser and instead are explicitly specified as strings.Additionally, the JSON spec requires that keys have quotes around them:
So
{key:'value'}is not valid JSON but is valid JS, while{"key":"value"}is valid JS and JSON.Examples of keywords and invalid/ambiguous keys:
Another example: