DRAFT
NoBracketNotationForObjects
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
CorrectionHere is what's right.
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"]
OriginWhere could this misconception come from?
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.