User Guide

Operators 25
Operators
Operators are elements that tell Lingo and JavaScript syntax scripts how to combine, compare, or
modify the values of an expression. Many of the operators in Director are shared between Lingo
and JavaScript syntax, and some are unique to each language.
Some types of operators include the following:
Arithmetic operators (such as +, -, /, and *)
Comparison operators (such as <, >, and >=), which compare two arguments
Logical operators (not, and, or), which combine simple conditions into compound ones
String operators (such as &, &&, and +), which join, or concatenate, strings of characters
Note: There are many more types of operators in JavaScript syntax than there are in Lingo,
and not all of them are covered in this reference. For more information on additional operators
in JavaScript 1.5, see one of the many third-party resources on the subject.
The items that operators act upon are called operands. In Lingo, there are only binary operators.
In JavaScript syntax, there are both binary and unary operators. A binary operator requires two
operands, one before the operator and one after the operator. A unary operator requires a single
operand, either before or after the operator.
In the following example, the first statement illustrates a binary operator, where the variables
x
and
y are operands and the plus (+) sign is the operator. The second statement illustrates a unary
operator, where the variable
i is the operand and ++ is the operator.
// JavaScript syntax
x + y; // binary operator
i++; // unary operator
For reference information on operators, see Chapter 13, “Operators,” on page 595.
Understanding operator precedence
When two or more operators are used in the same statement, some operators take precedence over
others in a precise hierarchy to determine which operators to execute first. This is called the
operators’ precedence order. For example, multiplication is always performed before addition.
However, items in parentheses take precedence over multiplication. In the following example,
without parentheses the multiplication in this statement occurs first:
-- Lingo syntax
total = 2 + 4 * 3 -- results in a value of 14
When parentheses surround the addition operation, addition occurs first:
-- Lingo syntax
total = (2 + 4) * 3 -- results in a value of 18
Descriptions of the types of operators and their precedence order follow. Operators with higher
precedence are performed first. For example, an operator whose precedence order is 5 is
performed before an operator whose precedence order is 4. Operations that have the same order
of precedence are performed left to right.