Javascript
JavaScript Fundamentals -- Objects in JavaScript
  •  

Creating New Objects

PRO

Creating objects in JavaScript is straightforward: you just need a set of opening and closing curly brackets. Inside the brackets you put key value pairs that store data.

const dog = {
    name: 'Duke'
}

The key is on the left side, name, and the value on the right, Duke. The value can be any data type you want, for example it could be a number, a boolean, a string, an array, or another object.

When declaring key names, you can use numbers, letters, and underscores, but dashes and spaces aren't allowed unless you wrap the key name in quotation marks.

You can read more about this in this blog post.