JSLint Messages – [{a}] is better written in dot notation.

In JavaScript, we can access an object member through the standard dot notation, i.e.

var a = {x:0};
var b = a.x;

And for trivial member names it is also possible to access it using the subscript (square-bracket) [] notation:

var a = {x:0};
var c = a['x'];

For a more detailed discussion of this, check out this excellent article at DevArchive.net by David Dorward.

JSLint prefers that you use the dot notation.  According to Douglas Crockford this is because “it is more compact and reads better”.

This is hard to argue against. In the above examples, the subscript notation takes up three more characters, and most programmers will be used to the dot notation manner. I think its fair to say that the use of objects in every-day programming far outstrips the use of arrays (although both are commonplace).

A Guide To JSLint Messages

This article is one of a series on the error and warning messages produced by JSLint.

2 thoughts on “JSLint Messages – [{a}] is better written in dot notation.

  1. Pingback: JSLint Messages – Bad Assignment | James Wiseman

  2. Pingback: JSLint – A Guide To JSLint Messages | James Wiseman

Leave a Reply