Operators
Arithmetic
Binary operators
+ Addition
- Subtraction
* Multiplication
/ Division (returns a floating-point value)
% Modulus (returns the integer remainder)
Unary operators
- Unary negation (reverses the sign)
++ Increment (can be prefix or postfix)
-- Decrement (can be prefix or postfix)
Assignment
= Assign
+= Add and assign
-= Subtract and assign
*= Multiply and assign
/= Divide and assign
%= Modulus and assign
&= Bitwise AND and assign
|= Bitwise OR and assign
^= Bitwise XOR and assign
<<= Left shift (zero fill) and assign
>>= Right shift (sign-propogating) and assign
>>>= Right shift (zero fill) and assign
Comparison
== Equal
!= Not equal
> Greater than
>= Greather than or equal to
< Less than
<= Less than or equal to
=== Identical (equal and of the same type)
!== Not identical
Conditional
? : Ternary comparison operator
condition ? val1 : val2 (Evaluates val1 if condition is true; otherwise, evaluates val2)
Boolean
- Short-circuit logical operations
- Evaluates the minimal number of
expressions necessary
- Partial evaluation (rather than full
evaluation)
&& and
|| or
! not (logical negation)
Bitwise
Binary operators
& And
| Or
^ Xor
<< Shift left (zero fill)
>> Shift right (sign-propogating); copies of the leftmost bit (sign bit) are shifted in from the left.
>>> Shift right (zero fill)
For positive numbers, >> and >>> yield the same result.
Unary operators
~ Not (inverts the bits)
String
= Assignment
+ Concatenation
+= Concatenate and assign
Examples
str = "ab" + "cd"; // "abcd"
str += "e"; // "abcde"
Misc
typeof
typeof operand
typeof (operand)
- Results in one of the following values: "function", "number",
"boolean", "string", "object", "undefined"