DEV Community

Discussion on: Bracket notation Vs dot notation in JavaScript objects

Collapse
 
lapalb profile image
Ashish Jha

As a general rule of Thumbs, Alwayys use dot notation excepts following two cases:

  1. To Access something like animalsList[animal], where key is variable.
  2. When key contains dash. person.birth-year will give an error, hence we will have to use person['birth-year']
Collapse
 
saran_chakravarthi profile image
Saran Chakravarthi

Thanks for pointing it out, Ashish.