Operator Overview

If you are a C, C++, or Java programmer, most of the JavaScript operators should already be familiar to you. Table 5-1 summarizes the operators; you can refer to this table for reference. Note that most operators are represented by punctuation characters such as + and =. Some, however, are represented by keywords such as delete and instanceof. Keyword operators are regular operators, just like those expressed with punctuation; they are simply expressed using a more readable and less succinct syntax.

In this table, the column labeled “P” gives the operator precedence and the column labeled “A” gives the operator associativity, which can be L (left-to-right) or R (right-to-left). If you do not already understand precedence and associativity, the subsections that follow the table explain these concepts. The operators themselves are documented following that discussion.

Table 5-1. JavaScript operators

P

A

Operator

Operand type(s)

Operation performed

15

L

.

object, identifier

Property access

L

[]

array, integer

Array index

L

( )

function, arguments

Function call

R

new

constructor call

Create new object

14

R

++

lvalue

Pre- or post-increment (unary)

R

--

lvalue

Pre- or post-decrement (unary)

R

-

number

Unary minus (negation)

R

+

number

Unary plus (no-op)

R

~

integer

Bitwise complement (unary)

R

!

boolean

Logical complement (unary)

R

delete

lvalue

Undefine a property (unary)

R

typeof ...

Get JavaScript: The Definitive Guide, Fourth 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.