Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Nobody seems to notice this, but using quotes stops you from error of using {foo:"bar"}. In JavaScript, {foo:"bar"} is not an Object, it is a code block containing a labeled code block with the label, foo, in it with a string, "bar". This is what {foo:"bar"} really means in JavaScript:

    {
      foo: {
        "bar";
      };
    }
Labels cannot be strings, so quoting them will help you catch this error earlier.


I'm not sure if your particular example is correct, but you're right that there are certain ambiguous cases involving labels and object literals.

There was a really good talk recently that touched on this, but I can't remember who gave it or what it was called.


a={foo:"bar"} creates an object called a with foo as a key mapping to "bar".


That's not a good reason. It's simple to spot that and enclose it in brackets.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: