Social Icons

Pages

Thursday, December 1, 2016

Introduction to Objects I 30/33

What Are Objects For?
Objects provide us with a way to represent real-world or virtual things. We can do this by storing information inside the object's properties. There are two basic ways to make objects:
Literal Notation, where we use
var Name = { };
Constructor Notation, where we use the keyword new.
We've given an example in literal notation to refresh your memory.

Instructions
Make a new object, spencer2, with the same properties but using constructor notation and the Object constructor.
var spencer = {
  age: 22,
  country: "United States"
};
var spencer2 = new Object();
spencer2.age= 22;
spencer2.country= "United States";

No comments:

Post a Comment