Comparison Operators
Equal (==
)
Description: Returns true if the operands are equal.
Examples:
3 == var1;
"3" == var1;
3 == "3";
Not Equal (!=
)
Description: Returns true if the operands are not equal.
Examples:
var1 != 4;
var2 != "3";
Strict Equal (===
)
Description: Returns true if the operands are equal and of the same type.
Examples:
3 === var1;
Strict Not Equal (!==
)
Description: Returns true if the operands are of the same type but not equal, or are of different types.
Examples:
var1 !== "3";
3 !== "3";
Greater Than (>
)
Description: Returns true if the left operand is greater than the right operand.
Examples:
var2 > var1;
"12" > 2;
Greater Than or Equal (>=
)
Description: Returns true if the left operand is greater than or equal to the right operand.
Examples:
var2 >= var1;
var1 >= 3;
Less Than (<
)
Description: Returns true if the left operand is less than the right operand.
Examples:
var1 < var2;
"2" < 12;
Less Than or Equal (<=
)
Description: Returns true if the left operand is less than or equal to the right operand.
Examples:
var1 <= var2;
var2 <= 5;
Logical Operators
Logical AND (&&
)
Logical OR (||
)
Logical NOT (!
)
False Values
false
0
""
(empty string)undefined
null
Assignment Operators
Assignment
x = y;
Addition Assignment
x += y; // x = x + y
Subtraction Assignment
x -= y; // x = x - y
Multiplication Assignment
x *= y; // x = x * y
Division Assignment
x /= y; // x = x / y
Remainder Assignment
x %= y; // x = x % y
Exponentiation Assignment
x **= y; // x = x ** y
Arithmetic Operators
Remainder (%
)
Description: Binary operator. Returns the integer remainder of dividing the two operands.
Increment (++
)
Description: Unary operator. Adds one to its operand.
Usage: Can be used as a prefix (++x
) or postfix (x++
) operator.
Decrement (--
)
Description: Unary operator. Subtracts one from its operand.
Unary Negation (-
)
Description: Unary operator. Returns the negation of its operand.
Unary Plus (+
)
Description: Unary operator. Attempts to convert the operand to a number, if it is not already.
Exponentiation Operator (**
)
Description: Calculates the base raised to the power of the exponent.
Arithmetic Operations on Numbers and Numbers as Strings
"10" + 1;
"10" - 1;
"10" * 1;
"10" / 1;
Conditional Operators
Ternary (?:
)
Other Operators
this
The this
keyword can cause confusion if not understood properly.
super
new
in
(for in)
instanceof
typeof
delete
Spread Operator (...
)
Bitwise Operators
Bitwise AND (&
)
Bitwise OR (|
)
Bitwise XOR (^
)
Bitwise NOT (~
)
Formula: (num * -1) - 1
Left Shift (<<
)
Formula: (a * 2^b)
Right Shift (>>
)
Formula: (a / 2^b)