O'Reilly logo

Eloquent JavaScript by Marijn Haverbeke

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

Basic Data Structures

Before we can write this program, we will need to go over a few new language features.

Properties

Some JavaScript values have other values associated with them. These associations are called properties. Every string, for example, has a property called length, which refers to an integer, the amount of characters in that string.

Properties can be accessed in two ways, either with brackets or using dot notation:

var text = "purple haze";
text["length"];
→ 11
text.length;
→ 11

The second way is a shorthand for the first, and it works only when the name of the property is a valid variable name—when it doesn’t have any spaces or symbols in it and does not start with a digit character.

Trying to read a property from the values null and ...

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