Chapter 22. JavaScript Operators

IN THIS CHAPTER

  • Understanding operator categories

  • Exploring the role of operators in script statements

  • Recognizing operator precedence

JavaScript is rich in operators: words and symbols in expressions that perform operations on one or two values to arrive at another value. Any value on which an operator performs some action is called an operand. An expression may contain one operand and one operator (called a unary operator), as in a++, or two operands separated by one operator (called a binary operator), as in a + b. Many of the same symbols are used in a variety of operators. The combination and order of those symbols are what distinguish their powers.

Note

The vast majority of JavaScript operators have been in the language since the very beginning. But, as you may expect from an evolving language, some entries were added to the lexicon as the language matured and gained wider usage. In the rest of this chapter, compatibility charts typically govern an entire category of operator. If there are version anomalies for a particular operator within a category, they are covered in the text. The good news is that modern browsers support the entire set of JavaScript operators.

Operator Categories

To help you grasp the range of JavaScript operators, we group them into seven categories. We assign a wholly untraditional name (connubial) to the second group—but a name that we believe correctly identifies its purpose in the language. Table 22-1 shows the operator types. ...

Get JavaScript® Bible, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.