An operator performs some computation on one or more variables. Operators can be classified as assignment, comparison, conditional, boolean, arithmetic, string, bitwise, and special. These operators are summarized in Table A-3
Operators | Description | Examples |
---|---|---|
assignment = += -= *= /= %= <<= >>= >>>= &= ^= |= | These operators assign a value to a variable. |
x = 3; y = fibonacci(10); x = "Hello." x = y; x += y // fills x with x + y x *= y // fills x with x * y |
comparison == != > >= < <= | These operators represent a relation between two expressions, evaluate to a boolean. |
x <= 10 5 != 4 // always evaluates // to true |
conditional ? : | This operator is a shorthand for if-then-else logic. |
y = (x < 0) ? 0 : x; // If x is less than 0 // then evaluate to 0, // otherwise evaluate to x |
boolean && || ! | With boolean values, these operators represent logical and, logical or, and logical not. |
if(p && ! (q || r )){ r = false; } // If p and not (q or r) // then let r = false. |
arithmetic + - * / % | With numbers, these operators perform basic arithetic. |
var x = 5 + 4; var y = x % 3; // "%" represents modulo. |
string + += == | These operators compare and concatenate strings. |
var s = "hello " + 2 + " the world."; if(s == "hello 2 the world"){ s += "!!"; } |
bitwise & | ^ << >> >>> | These operators treat numbers as bit fields. |
var x = 1 | 4 >> 3; |
special [typeof . function | These operators manage language constructs such as membership, type resolution, and function resolution. |
var a = Employee.FirstName; if (o typeof Employee){ o.FirstName = "John"; } |
18.117.77.76