𝗝𝗮𝘃𝗮𝗦𝗰𝗿𝗶𝗽𝘁 𝗢𝗽𝗲𝗿𝗮𝘁𝗼𝗿𝘀 𝗘𝘅𝗽𝗹𝗮𝗶𝗻𝗲𝗱
Operators are symbols for operations on values and variables. You use them to build logic in your code.
Math Operators
- Addition
- Subtraction
- Multiplication
- / Division
- % Remainder
- ** Exponent
Increment and Decrement
- ++x: Adds 1 first.
- x++: Adds 1 after use.
Assignment Operators
- = Sets a value.
- += Adds then sets.
- -= Subtracts then sets.
Comparison Operators These return true or false.
- === Checks value and type. Use this for safety.
- == Checks value only.
Greater than.
- < Less than.
Logical Operators
- && AND: Both must be true.
- || OR: One must be true.
- ! NOT: Flips true to false.
Shortcuts
- Ternary: Short if-else.
- Nullish Coalescing (??): Sets default value for null.
- Optional Chaining (?.): Reads properties without errors.
Extra Tools
- typeof: Checks the data type.
- Spread (...): Copies or merges arrays.
Source: https://dev.to/dev_saravanan_journey/javascript-operators-explained-with-examples-3dfn