O'Reilly logo

JavaScript Quick Syntax Reference by Mikael Olsson

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 9

image

Objects

An object is a collection of named values known as properties. Properties can be either variables that hold the state of the object, or functions that define what the object can do. The appeal of objects is that they provide functionality while hiding their inner workings. All you need to know is what an object can do for you, not how it does it.

Object Properties

An empty object can be created using the new directive in the following explicit manner.

var box = new Object();

Properties for an object are created automatically when they are assigned to, using either the dot notation or the array notation.

box.x = 2;box["y"] = 3; ...

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