An expression consists of operators and operands. Operators are special symbols commonly used in expressions, denoting the operations to be performed with the operands they are adjacent to. Operands can be variables or function invocations which return a value that can be operated on by the relevant operators
Expressions must operate on compatible variable types. Type checking is performed at compile time to guarantee that no runtime errors occur due to an invalid mix of types. Some expression examples follow.
//Variable c is assigned the sum of a and b. c = a + b
// myVariable is assigned the product of 12 by the sum of yourVariable and ourVariable. myVariable = 12 * (yourVariable + ourVariable)
employeeName = firstName + " " + lastName
Notice the parentheses in the expression example above. Parentheses play a role in precedence. Precedence is the order in which operations take place in a mathematical equation. This is sometimes called order of operations. Any operation inside parentheses is evaluated first, and then followed by other operations.
myVariable = 12 * (yourVariable + ourVariable)
For further information on the different operators, please see Operators.
<Boolean expression> ? <expression> : <expression>
myResult = (show = 1) ? "on" : "off"
In this example, the variable myResult is assigned the value "on" if the value of the variable show is equal to 1. Otherwise, "off" is assigned to myResult.