O'Reilly logo

JavaScript® Programmer's Reference by Alexei White

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 4. Expressions, Operators, and Statements

If the data types discussed in the previous chapter are the bricks inside a building, then operators, expressions, and statements are the mortar holding them together. JavaScript is a very modern language in the types of operations it supports, and you will find that many of the same types of statements and expressions can be used as in other languages.

JavaScript Expressions

In mathematics, an expression is any coherent combination of symbols that can be resolved to a single value. This is true in the programming sense of the word as well but can include variables, literals, operators, and functions that can be evaluated by the interpreter to a single value. For example, the following list contains a set of example expressions in JavaScript:

"Hello"
myValue
myValue * 100
function() {return null;}
100.3231E2

An expression is a combination of symbols, but you can also say that it is its value, or it has a particular value. A value doesn't have to be something primitive like a number or string literal. It can also be a reference to an object like a DOM node or function.

Depending on what the evaluated result is, the expression is of that type. For example, if the expression results in a Boolean value (a logical operation), it is a logical expression. If the expression results in a numeric value, it is an arithmetic expression and so on.

As in mathematics, very often you use symbols called operators inside expressions to perform a calculation. ...

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