Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
The simplest expressions, known as primary expressions, are those that stand alone—they do not include any simpler expressions. Primary expressions in JavaScript are constant or literal values, certain language keywords, and variable references.
Literals are constant values that are embedded directly in your program. They look like these:
1.23 // A number literal "hello" // A string literal /pattern/ // A regular expression literal
Reserved words like true,
false, null, and this are primary expressions.
Finally, the third type of primary expression is the bare variable reference:
i // Evaluates to the value of the variable i. sum // Evaluates to the value of the variable sum.
When any identifier appears by itself in a program, JavaScript
assumes it is a variable and looks up its value. If no variable with that
name exists, the expression evaluates to the undefined value. In the strict mode of
ECMAScript 5, however, an attempt to evaluate a nonexistent variable
throws a ReferenceError instead.