[JavaScript] Use dot notation when accessing or setting properties

#1

JavaScript allows property access using either dot notation or square-bracket notation.

Use dot notation when accessing or setting properties:

// good
person.givenName = "Alex";
var name = person.givenName;
    
// bad
person["givenName"] = "Alex";
var name = person["givenName"];

Reasoning: improves readability; works better with aggressive JavaScript minimizers/uglifiers

Reference: Airbnb JavaScript Style Guide, ESLint config dot-notation

0 Likes