|+||Adds two values together.|
|-||Subtracts one value from another.|
|*||Multiplies two values together.|
|/||Divides one value by another.|
|%||Calculates the remainder after one value is divided by another.|
The following examples show each of these operators in action.
// Variables to use in expressions. var a = 10, b = 20, c = 0; c = a + b; // c will equal 30. c = b - a; // c will equal 10. c = a * b; // c will equal 200. c = b / a; // c will equal 2. c = b % a; // c will equal 0.
var a = 10; // a gets set to 10. var b = 2; b += 5; // b gets set to 7. var c = 10; c -= 4; // c gets set to 6. var d = 2; d *= 2; // d gets set to 4. var e = 20; e /= 5; // e gets set to 4. var f = 5; f *= 2; // f gets set to 1.
The '+' operator can also be used to concatenate two strings or a string and a number.
var a, b, c, d, e; a = "Hello "; b = "world"; c = 5; d = a + b; // d contains the string "Hello world". e = d + c; // e contains the string "Hello world5".
Relational operators compare two values and are used, for example, in 'if' statements, which are described in the next section on Decision Making. The result of the comparison is either True or False.
|==||Evaluates to True if the two values are equal.|
|===||Evaluates to True if the two values are identical in value and type.|
|!=||Evaluates to True if the two values are not equal.|
|!==||Evaluates to True if the two values are not identical in value or of the same type.|
|>||Evaluates to True if the first value is greater than the second.|
|<||Evaluates to True if the first value is less than the second.|
|>=||Evaluates to True if the first value is greater than or equal to the second.|
|<=||Evaluates to True if the first value is less than or equal to the second.|
Logical operators are used where you want to test more than one condition at the same time, for example, in an 'if' statement. The exception to this is the 'not' operator, which is used to check if a condition is not true. This could be used in conjunction with the other Logical Operators.
|&&||Evaluates to True if both conditions are True. The equivalent of saying 'and'.|
|||||Evaluates to True if either condition is True. The equivalent of saying 'or'.|
|not||Evaluates to True if the condition is not True.|