𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗢𝗽𝗲𝗿𝗮𝘁𝗼𝗿𝘀 𝗚𝘂𝗶𝗱𝗲
JavaScript operators are symbols. They perform actions on values and variables. You use them to build logic.
Use arithmetic operators for math.
- Addition: 5 + 2 = 7
- Subtraction: 5 - 2 = 3
- Multiplication: 5 * 2 = 10
- / Division: 5 / 2 = 2.5
- % Modulus: 5 % 2 = 1
- ** Exponentiation: 5 ** 2 = 25
Use assignment operators to set values.
- = assign
- += add and assign
- -= subtract and assign
- *= multiply and assign
- /= divide and assign
- %= remainder and assign
Use comparison operators to check values.
- == equal to
- === equal value and type
- != not equal
- !== not equal value or type
greater than
- < less than
= greater than or equal to
- <= less than or equal to
Use logical operators for conditions.
- && logical AND
- || logical OR
- ! logical NOT
- ?? nullish coalescing
Use bitwise operators for binary bits.
- & bitwise AND
- | bitwise OR
- ^ bitwise XOR
- ~ bitwise NOT
- << left shift
signed right shift
unsigned right shift
Use these for text and short logic.
- joins strings
- ?: ternary operator
Use special operators for specific tasks.
- typeof checks the type
- instanceof checks the class
- delete removes a property
- in checks for a property
- ?. accesses nested values
- ... expands arrays or objects
Source: https://dev.to/raja_b_0c9d242e2c26cf063b/javascript-operators-2k32