Operators review

Learning JavaScript's standard operators is essential to learning the language. Operators are used to manipulate data, which is one of the most common tasks performed in a program.

Unary operator

A unary operator works on a single operand. The three JavaScript unary operators are:

Both the increment and decrement operators can be used in either prefix or postfix modes. In prefix mode, the variable is incremented (or decremented) before any other operations are performed. In postfix mode, other operations are executed before the variable is incremented or decremented.

Compound assignment operator

The compound assignment operator is shorthand notation for the mathematical operators. Its syntax is:

variable (op)= operand;

where op is a standard JavaScript mathematical operator.

Comparison and logical operators

The comparison operators compare two values for a specific relationship. If the relationship exists, the expression evaluates to true. JavaScript's standard comparrason operators include tests for equality (==), greater than (>), less than (<), greater than or equal to (>=), less than or equal to (<=) and not equal to (!=) relationships.

The logical operators allow you to string together multiple conditional statements to create a complex conditional statement. JavaScript's logical operators are the logical AND (&&), logical OR (||) and logical NOT (!).

'If' statement

The 'if' statement is used to create conditionals in a script. If the conditional statement evaluates to true, the the statement block following the conditional will be executed. If it is false, any statements included in an optional 'else' clause will be executed.

Operator precedence

Operator precedence dictates the order in which JavaScript statements are evaluated. From greatest to least precedence, the list of JavaScript operators is as follows: