From the course: Coding for Visual Learners: Learning JavaScript from Scratch

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Introduction to JavaScript objects

Introduction to JavaScript objects

- [Narrator] JavaScript uses a data structure called object that helps to organize data together. There're a couple of ways of creating an object in JavaScript. One way is by using curly brackets. So here, outside of the setup and draw functions, I will be creating a new variable called colors, and we will be using curly brackets to initialize a new object. These curly brackets are called object initializers. They create an empty object. You will hold a reference to the object by using the variable colors in this example. Now, we can add properties to this colors object by providing the desired property names after the dots. This is called dot notation. So here, on this variable, I can create other variables, actually called properties at this point, because these are variables that live on the object. And I can assign values to these variables or properties. So let's give this a value of 55. Let's create another property…

Contents