Skip to main content

Operators

Vyshnavi0809
EditReport

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

Telemetry Integration

Completed working through this block? Sync progress to workspace.