Dot Operators

Hey, I am very new to learning javascript, and the course I am taking did not touch on dot operators for very long. Could someone please explain dot operators for me more in depth? Thanks! :slight_smile:

object.property

The dot operator is the notation used to access properties that exist within the object context.

const lassie = {
  breed: 'Collie',
  color: 'ginger/white',
  weight: '25kg',
  age: '6yr'
}

The object literal above has own properties, ‘breed’, ‘color’, ‘weight’, ‘age’. We access them using dot notation:

console.log(lassie.breed)    //  Collie
console.log(lassie.color)    //  ginger/white
console.log(lassie.weight)   //  25kg
console.log(lassie.age)      //  6yr
1 Like