Coffee School Objects

Code Editor

Preview

Console Log:

Objects

Time to complete: 5 minutes

In JavaScript you can have objects, which can have properties and methods. They can be used to represent real-world object, such as a user or a car, and allow us to manipulate it. A property can either be a variable or a function, in which case it is called a method.

lets create an object

var myUser = new Object();
myUser.name = "Tom";
myUser.age = 16;

console.log(myUser.name + " is aged " + myUser.age);

You can now access modify the name and age properites of myUser as you wish. We will expand upon the use of objects in later lessons.