Skip to content

Latest commit

 

History

History
133 lines (122 loc) · 7.29 KB

File metadata and controls

133 lines (122 loc) · 7.29 KB

Operators

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

Binary Operators

Compound assignment operators

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`

Comparison operators

Operator Description Examples returning true
Equal (==) Returns true if the operands are equal.

3 == var1

"3" == var13 == '3'

Not equal (!=) Returns true if the operands are not equal. var1 != 4
var2 != "3"
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"
3 !== '3'
Greater than (>) Returns true if the left operand is greater than the right operand. var2 > var1
"12" > 2
Greater than or equal (>=) Returns true if the left operand is greater than or equal to the right operand. var2 >= var1
var1 >= 3
Less than (<) Returns true if the left operand is less than the right operand. var1 < var2
"2" < 12
Less than or equal (<=) Returns true if the left operand is less than or equal to the right operand. var1 <= var2
var2 <= 5

Unary Operators

typeof
-
!

Ternary Operators

console.log(true ? 1 : 2);
// → 1
console.log(false ? 1 : 2);
// → 2