Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save afaqahmedkhan/be136e4669eb503e72a408ef3b9b3a3a to your computer and use it in GitHub Desktop.
Save afaqahmedkhan/be136e4669eb503e72a408ef3b9b3a3a to your computer and use it in GitHub Desktop.
Object Oriented Programming: Use Dot Notation to Access the Properties of an Object
let dog = {
name: "Spot",
numLegs: 4
};
// Add your code below this line
console.log(dog.name);
console.log(dog.numLegs);
@afaqahmedkhan
Copy link
Author

The last challenge created an object with various properties, now you'll see how to access the values of those properties. Here's an example:

let duck = {
  name: "Aflac",
  numLegs: 2
};
console.log(duck.name);
// This prints "Aflac" to the console

Dot notation is used on the object name, duck, followed by the name of the property, name, to access the value of "Aflac".

Print both properties of the dog object below to your console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment