O'Reilly logo

JavaScript: The Good Parts by Douglas Crockford

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

Expressions

image with no caption

The simplest expressions are a literal value (such as a string or number), a variable, a built-in value (true, false, null, undefined, NaN, or Infinity), an invocation expression preceded by new, a refinement expression preceded by delete, an expression wrapped in parentheses, an expression preceded by a prefix operator, or an expression followed by:

  • An infix operator and another expression

  • The ? ternary operator followed by another expression, then by :, and then by yet another expression

  • An invocation

  • A refinement

The ? ternary operator takes three operands. If the first operand is truthy, it produces the value of the second operand. But if the first operand is falsy, it produces the value of the third operand.

The operators at the top of the operator precedence list in Table 2-1 have higher precedence. They bind the tightest. The operators at the bottom have the lowest precedence. Parentheses can be used to alter the normal precedence, so:

2 + 3 * 5 === 17
(2 + 3) * 5 === 25

Table 2-1. Operator precedence

. [] ( )

Refinement and invocation

delete new typeof + - !

Unary operators

* / %

Multiplication, division, remainder

+ -

Addition/concatenation, subtraction

>= <= > <

Inequality

=== !==

Equality

&&

Logical and

||

Logical or

?:

Ternary

image with no caption

The values ...

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