Operators and Expressions

Beginner
60 XP
20 min
Lesson Content

Operators in JavaScript

Operators perform operations on values and variables. JavaScript has several types of operators.

Arithmetic Operators

  • + Addition: 5 + 3 = 8
  • - Subtraction: 10 - 4 = 6
  • * Multiplication: 3 * 4 = 12
  • / Division: 15 / 3 = 5
  • % Modulus (remainder): 10 % 3 = 1
  • ** Exponentiation: 2 ** 3 = 8

Comparison Operators

  • == Equal to (loose)
  • === Equal to (strict)
  • != Not equal
  • > Greater than
  • < Less than
  • >= Greater than or equal
  • <= Less than or equal

Logical Operators

  • && AND - both must be true
  • || OR - at least one must be true
  • ! NOT - reverses boolean
Example Code

Use various operators to perform calculations and comparisons

// Arithmetic operations
let a = 8;
let b = 3;
console.log('Addition:', a + b);
console.log('Subtraction:', a - b);
console.log('Multiplication:', a * b);
console.log('Division:', a / b);
console.log('Modulus:', a % b);

// Comparison
console.log('a > b:', a > b);
console.log('a === b:', a === b);

// Logical
let x = true;
let y = false;
console.log('x && y:', x && y);
console.log('x || y:', x || y);

Expected Output:

Addition: 11
Subtraction: 5
Multiplication: 24
Division: 2.6666666666666665
Modulus: 2
a > b: true
a === b: false
x && y: false
x || y: true
Study Tips
  • Read the theory content thoroughly before practicing
  • Review the example code to understand key concepts
  • Proceed to the Practice tab when you're ready to code