bramus/ria-course-materials — Issue #1: Suggestion for the “Accessing Object Properties” chapter
Author: mathiasbynens
Created: 2012-03-05 08:18:45+00:00
State: open

This is just a suggestion, related to https://github.com/bramus/ria-course-materials/blob/09b129db8080437ff9f5ff234d7648d86186300c/01.advanced.js.html#L562-587.

Personally I prefer quoting all property names (it’s a coding style thing). That way they get pretty syntax highlighting in most editors, and it’s consistent with cases where you’re forced to use quotes anyway. The slides mention a few of these cases.

However, using quotes consistently also avoids confusion in cases where numeric literals are being used as property names, e.g.:

```js
var object = {
12e34: 'f7u12'
};
object.12e34; // SyntaxError
object['12e34']; // undefined

// on the other hand, if you had just used quotes (and thus string literals for property names), there wouldn’t be a problem:
object = {
'12e34': 'yay'
};
object['12e34']; // 'yay'
```

TL;DR Quoting property names all the time doesn’t cost you anything, but it does help you avoid a lot of confusion and potential bugs.

FWIW, I’ve written a bit about the subject: http://mathiasbynens.be/notes/javascript-properties And created a tool: http://mothereff.in/js-properties Perhaps these would be a useful reference.