Skip to main content

Operators

Operators are symbols or keywords used to perform operations on variables and values. Understanding the different types of operators and their precedence is crucial for writing efficient code.

Types of Operators​

Most programming languages support the following types of operators:

  1. Arithmetic Operators
  2. Comparison Operators
  3. Logical Operators
  4. Assignment Operators
  5. Bitwise Operators
  6. Unary Operators
  7. Ternary (Conditional) Operators

JavaScript Operators Overview​

JavaScript supports a wide range of operators that help you perform various tasks:

1. Arithmetic Operators​

These operators are used to perform mathematical operations.

Arithmetic Operators in JavaScript
let a = 10;
let b = 5;

console.log(a + b); // Addition: 15
console.log(a - b); // Subtraction: 5
console.log(a * b); // Multiplication: 50
console.log(a / b); // Division: 2
console.log(a % b); // Modulus: 0
console.log(a ** 2); // Exponentiation: 100

2. Comparison Operators​

These operators compare two values and return a Boolean (true or false).

Comparison Operators in JavaScript
console.log(a > b); // true
console.log(a < b); // false
console.log(a == 10); // true (loose equality)
console.log(a === "10"); // false (strict equality)

Operator Precedence​

Understanding operator precedence is important to ensure expressions evaluate as intended. JavaScript evaluates operators from highest to lowest precedence.

Mermaid Diagram of Operator Precedence:


Feedback and Support