| How to check if two items are equal in vanilla JS | 5/25 |
| Operator Lookup | 11/14 |
| Comma Operator in JavaScript | 10/7 |
| MDN Expressions and operators | 1/2/2020 |
| Shorthand operator | Meaning | |
|---|---|---|
| Assignment | x = y |
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, (modulo) | x %= y |
x = x % y |
| Exponentiation assignment | x **= y |
x = x ** y |
| Left shift assignment | x <<= y |
x = x << y |
| Right shift assignment | x >>= y |
x = x >> y |
| Unsigned right shift assignment | x >>>= y |
x = x >>> y |
| Bitwise AND assignment | x &= y |
x = x & y |
| Bitwise XOR assignment | x ^= y |
x = x ^ y |
| Bitwise OR assignment | `x | = y` |
| Operator | Description | Examples returning true |
Equal (==) |
Returns true if the operands are equal. |
|
Not equal (!=) |
Returns true if the operands are not equal. |
var1 != 4
|
Strict equal (===) |
Returns true if the operands are equal and of the same type.
See also Object.is and
sameness in JS. |
3 === var1
|
Strict not equal (!==) |
Returns true if the operands are of the same type but not equal,
or are of different type. |
var1 !== "3"
|
Greater than (>) |
Returns true if the left operand is greater than the right
operand. |
var2 > var1
|
Greater than or equal (>=) |
Returns true if the left operand is greater than or equal to
the right operand. |
var2 >= var1
|
Less than (<) |
Returns true if the left operand is less than the right operand. |
var1 < var2
|
Less than or equal (<=) |
Returns true if the left operand is less than or equal to the
right operand. |
var1 <= var2
|
| typeof | |
| - | |
| ! |
console.log(true ? 1 : 2);
// → 1
console.log(false ? 1 : 2);
// → 2