O'Reilly logo

The JavaScript PocketGuide by Lenny Burdette

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

6. Objects

Understanding objects is crucial to writing well-organized, expressive JavaScript. If you’ve used other languages such as Java or ActionScript, JavaScript may seem like it’s missing a lot of language features such as classes and modules. But objects in JavaScript are flexible and powerful enough that you don’t often miss those features. Sometimes you can even emulate missing language features with clever uses of objects and functions.

Basics

The best way to create an object is to use an object literal.

var myObject = {};

You can create an object with properties by listing them in the object literal, separating property names and values with colons.

Tip

Notice that each property: value pair is separated by a comma, but make sure ...

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