In JavaScript, operators are special symbols or keywords that are used to perform operations on variables and values. They allow you to manipulate data, compare values, or assign values to variables.

Types of Operators in JavaScript:

  1. Arithmetic Operators: Used for mathematical calculations (e.g., addition, subtraction).
  2. Assignment Operators: Used to assign values to variables (e.g., =, +=).
  3. Comparison Operators: Used to compare two values (e.g., ==, >, <=).
  4. Logical Operators: Used to perform logical operations, often with Boolean values (e.g., &&, ||).
  5. Bitwise Operators: Perform operations on binary representations of numbers (e.g., &, |).
  6. Unary Operators: Operate on a single operand (e.g., increment ++, decrement -).
  7. Ternary Operator: A shorthand for if-else statements (e.g., condition ? expr1 : expr2).
  8. Spread Operator: Expands elements in arrays and objects (e.g., ...).
  9. Nullish Coalescing Operator: Checks for null or undefined (e.g., ??).

1. Arithmetic Operators

Used to perform mathematical calculations.

Operator Description Example
+ Addition 5 + 27
- Subtraction 5 - 23
* Multiplication 5 * 210
/ Division 5 / 22.5
% Modulus (Remainder) 5 % 21
** Exponentiation 2 ** 38

2. Assignment Operators

Used to assign values to variables.