4 ms·
Other than being idiomatic, is there any advantage to quoting or not quoting key names in JS?
by dathanb82 10y ago
Other than being idiomatic, is there any advantage to quoting or not quoting key names in JS?
- jorde 10y agoQuoted keys allows more variety in the keys (e.g. "Content-Type") but is more annoying to use if all your JS code is written in camelCase (headers["Content-Type"] vs headers.contentType).
- mjmasn 10y agoMinor reasons but a) it looks untidy (to me), and b) for example if I want to change: foo = { "bar": true, "baz": false } to: foo.bar = true; foo.baz = false; then I have extra quotes to delete. Those half seconds add up over a year! I guess you could argue the opposite though, that this looks messy: let headers = { Expires: 0, 'Content-Type': 'application/json' } Which leads me to believe it's a matter of personal preference, and you should just pick one and stick to it :) And look, there's even an eslint rule for it: http://eslint.org/docs/rules/quote-props http://eslint.org/docs/rules/quote-props