O'Reilly logo

Jump Start JavaScript by Don Nguyen, Ara Pehlivanian

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 4Objects and Functions

In the previous chapter, we looked at arrays. Now we’re going to look at objects, which are similar to arrays in that they are containers for collections of data. Though there are similarities―arrays are actually a type of object―there are also some significant differences.

Objects

Creating an Object

As with arrays, there are a couple of ways to create objects, and, just like arrays, one is preferred over the other. So even though you can do this:

        var myObject = new Object();      

it is much better to do this:

        var myObject = {};      

The latter is simpler, safer, and therefore preferable. If you remember from Chapter 3, Array() can be overwritten for malicious purposes. So can Object(), which is why it's safer to use ...

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