NoBracketNotationForObjects
DRAFT

Misconception:

The notation with square brackets (e.g., obj[prop]) cannot be used to access properties of an object.

Incorrect

Square brackets cannot be used to access properties of an object

Correct

Square brackets can be used to access properties of an object

Correction
Here is what's right.

One can have access, to read or to modify, the properties of an object with two different notations:

  • dot notation, e.g. obj.field_name
  • bracket notation, e.g. obj["fieldname"]

Origin
Where could this misconception come from?

Students might be familiar with the square bracket notation for accessing elements inside arrays and thus believe that the syntax is limited to arrays.

Stay up-to-date

Follow us on  twitter to hear about new misconceptions.