DEV Community

Code_Regina
Code_Regina

Posted on

|JavaScript| JavaScript: Object Literals

          -Introducing Object Literals
          -Creating Object Literals
          -Modifying Objects 
Enter fullscreen mode Exit fullscreen mode

Introducing Object Literals

Objects are collection of properties. Properties are a key-value pair.
Rather than accessing data using index, we use custom keys.


const fitBitData = {

totalSteps : 308272, 
totalMiles : 211.7, 
avgCalorieBurn : 5755,
workoutsThisWeek : '5 of 7',
avgGoodSleep : '2 : 13'
};

Enter fullscreen mode Exit fullscreen mode

Creating Object Literals

All data types can be used to create object literals


let comment = {

username: 'somethingSpecial43',
downVotes : 10,
upVotes : 211,
netScore : 120,
commentText : 'Taste like chicken', 
tags : ['#hilarious', '#funny', '#silly'],
isGilded : false
};

Enter fullscreen mode Exit fullscreen mode

Top comments (0)