Master Code
On The Go

Learn. Practice. Build.

Quest 1 • Lesson 3

➕ JavaScript Operators & Expressions

Operators are the verbs of JavaScript. Learn how to do math, compare values, and combine conditions.

An operator performs an action on values (called operands). JavaScript has five main groups you'll use every day.

"An expression is anything that produces a value. 2 + 3 is an expression. 2 + 3 * 4 is also an expression — with a specific answer."

🔢 1. Arithmetic Operators

Basic math on numbers:

OperatorNameExampleResult
+Addition5 + 38
-Subtraction5 - 32
*Multiplication5 * 315
/Division15 / 35
%Modulus (remainder)7 % 31
**Exponent2 ** 38
console.log(5 + 3);    // 8
console.log(10 - 4);   // 6
console.log(3 * 4);    // 12
console.log(20 / 5);   // 4
console.log(7 % 3);    // 1 (remainder of 7 ÷ 3)
console.log(2 ** 4);   // 16 (2 to the power of 4)

💡 Modulus (%) is underrated. It's how you check if a number is even or odd: n % 2 === 0 means even.

⚖️ 2. Comparison Operators

Compare two values, always return true or false:

OperatorMeaningExampleResult
===Strict equal5 === 5true
!==Strict not equal5 !== 3true
>Greater than10 > 5true
<Less than3 < 1false
>=Greater or equal5 >= 5true
<=Less or equal4 <= 3false

⚠️ Always use === not ==. The double equals does "type coercion" and produces surprising results. "5" == 5 is true, but "5" === 5 is false. Stick with triple equals.

🧠 3. Logical Operators

Combine multiple conditions:

OperatorNameMeaning
&&ANDTrue only if both sides are true
||ORTrue if either side is true
!NOTFlips true to false and vice versa
console.log(true && true);    // true
console.log(true && false);   // false
console.log(true || false);   // true
console.log(false || false);  // false
console.log(!true);           // false
console.log(!false);          // true

💡 Real use case: if (age >= 18 && hasID) — both must be true for entry.

📝 4. Assignment Operators

Shortcuts for updating variables:

let score = 0;

score = 10;      // simple assign
score += 5;      // same as: score = score + 5  → 15
score -= 3;      // same as: score = score - 3  → 12
score *= 2;      // same as: score = score * 2  → 24
score /= 4;      // same as: score = score / 4  → 6

console.log(score);  // 6

📖 5. String Concatenation vs. Template Literals

You have two ways to combine strings with variables:

const name = "Alice";
const age = 25;

// Old way — string concatenation with +
console.log("My name is " + name + " and I'm " + age + ".");

// Modern way — template literal with backticks
console.log(`My name is ${name} and I'm ${age}.`);

Both produce the same output. But the second is cleaner, handles multi-line text easily, and lets you embed expressions directly:

const price = 12.5;
const qty = 3;
console.log(`Total: $${(price * qty).toFixed(2)}`);  // Total: $37.50

💡 Always use template literals in modern JavaScript. String concatenation with + is fine, but backticks are easier to read and less error-prone.

🚀 Try It Live

Edit the code below and click Run to see the output.

Click "Run Code" to see the output.

🧮 Interactive Operator Playground

Enter two numbers and click any operator to see the result.

Result: 10 + 3 = 13

✨ Challenge: Even or Odd

Write code that takes a number and prints whether it's even or odd using the % operator.

📚 What's Next?

📤 Share This Lesson

Help others learn JavaScript!

❤️ Support Free Education

This course is 100% free. If it helps you, consider buying me a coffee.

☕ Buy Me a Coffee
← Back to JavaScript Course Hub