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

More on Types

The previous should enable you to write and understand simple JavaScript programs. However, before closing the chapter, a few more subtleties have to be cleared up.

Undefined Values

It is possible to define a variable using var something;, without giving it a value. What happens when you take the value of such a variable?

var mysteryVariable;
mysteryVariable;
→ undefined

In terms of tentacles, this variable ends in thin air—it has nothing to grasp. When you ask for the value of an empty place, you get a special value named undefined. Functions that do not return a specific value but are called for their side effects, such as print and alert, also return an undefined value.

There is also a similar value, null, whose meaning is “this value ...

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