An expression consists of an operand on its own, or a combination of operators and operands. An operand may be a constant value, a functional value, or a variable. Evaluating expressions can easily cause side effects, especially when functions are invoked.
Expressions are the contexts within which JavaScript operates on entities in its object model. There are a variety of different kinds of expressions according to whether you are referring to the destination or source of an assignment or reference.
Expressions fall into one of several categories according to the operator used in the expression.
The following expression types are defined in the ECMAScript standard:
| Type | Description |
|---|---|
| Primary | A Primary Expression is a specific object, identifier or literal and may also be the result of evaluating another nested expression when it is surrounded by the grouping operators (round brackets). |
| Left-Hand-Side | This kind of expression identified the destination of an assignment (even if that assignment operation is only implied). |
| Postfix | Postfix expressions operate on Left-Hand-Side (sometimes called LValue) expressions. |
| Unary | Unary expressions can also be considered to be prefix expressions and also operate on LValues. |
| Multiplicative | Multiplicative expressions use the multiplicative operators to yield a result by operating on two other values which may themselves be nested. |
| Additive | Additive expressions use the additive operators to yield a result by operating on two other values which may be nested expressions. |
| Shift | Shifts the left value by an amount specified by the right value. |
| Relational | Relational expressions yield a Boolean result according to the relational test of the values either size of the operator. |
| Bitwise | Bitwise expressions perform a bit by bit operation across the entire integer width of the values. |
| Logical | Logical operators perform a test of the Boolean value of the two operands either side of the operator. |
| Conditional | Conditional expressions test a logical expression and perform one of two possible alternative code blocks. |
| Assignment | Assignment expressions can be broken down into a two-operand expression with the result being assigned to the value on the left. |
| Comma | Comma expressions occur rarely and are used to evaluate several expressions at once. |
The operators are discussed in detail in individual topics. Refer to those topics for more details.
Expressions resolve eventually to a primary expression, which has a distinct value.
In a compound expression, the precedence (or "Who's on first") is governed by the operator-selected for that sub-expression. However that operator-driven precedence model can be overridden by use of the grouping operators.
| See also: | Associativity, Bit-field, Exception, JavaScript language, Side effect |
| Prev | Home | Next |
| export | Up | Expression statement |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. | ||