Curriculum / Fundamentals / Lesson 04

Operators & Expressions

Perform calculations, compare values, and combine logic with JavaScript's operators.

4 of 30
beginner 📖 6 min read 🎯 4 questions

What is an Operator?

An operator is a symbol that tells JavaScript to perform a specific mathematical, relational, or logical operation and produce a result. An expression is any valid piece of code that resolves to a value — often built with operators.

For example: 5 + 3 is an expression that uses the addition operator +.

💡 Key insight Expressions are the building blocks of programs. Every time you write let total = price * quantity;, you're using operators to create a new value.

Arithmetic Operators

Use these to perform math operations on numbers.

Assignment Operators

Assign values to variables, often combined with arithmetic.

Comparison Operators

Compare two values and return a boolean (true or false).

⚠️ Use === and !== Always prefer strict equality === over loose == to avoid unexpected type coercion bugs.

Logical Operators

Combine multiple conditions or invert boolean values.

Operator Precedence

Just like in math, operators have a precedence that determines the order in which they are evaluated. Multiplication and division happen before addition and subtraction.

let result = 5 + 3 * 2; // 11, not 16

Use parentheses () to make your intention clear and override precedence.

let result2 = (5 + 3) * 2; // 16

Common Mistakes

Quick Quiz

1. What is the result of 10 % 3?

2. Which operator should you use for strict equality?

3. What does true && false return?

4. What is the value of x after let x = 5; x += 2;?

Summary

Back to curriculum