DEV Community

Cover image for TIL: JavaScript Objects & Accessing Properties
Vicki Langer
Vicki Langer

Posted on

TIL: JavaScript Objects & Accessing Properties

Today, I created my very first JavaScript object!

Liquid error: internal

var myDog = {
  "name": "Cheeto",
  "enemies": "Puppy the cat"
};
Enter fullscreen mode Exit fullscreen mode

I was also able to access properties with dot and bracket notation

>var nameval = myDog.name; // "Cheeto"
>var enemiesval = myDog.enemies; // "Puppy the cat"
Enter fullscreen mode Exit fullscreen mode
var nameValue = myDog["Name"]; // Cheeto
var enemiesValue = myDog['enemies']; // Puppy the cat 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)