O'Reilly logo

Object-Oriented JavaScript - Second Edition by Stoyan Stefanov, Kumar Chetan Sharma

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Objects

Now that you've mastered JavaScript's primitive data types, arrays, and functions, it's time to make true to the promise of the book title and talk about objects.

In this chapter, you will learn:

  • How to create and use objects
  • What are the constructor functions
  • What types of built-in JavaScript objects exist and what they can do for you

From arrays to objects

As you already know from Chapter 2, Primitive Data Types, Arrays, Loops, and Conditions, an array is just a list of values. Each value has an index (a numeric key) that starts from zero and increments by one for each value.

> var myarr = ['red', 'blue', 'yellow', 'purple'];
> myarr;
 ["red", "blue", "yellow", "purple"].
> myarr[0];
"red"
> myarr[3];
"purple"

If you put the indexes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required