Loading...
Loading...
The building blocks of computation. Combine values, compare data, and control logic.
Before you can build anything in JavaScript you need the vocabulary the language is built on: what JavaScript is, how to store data, how to combine it, how values change type, and how to talk to the user. Every later module assumes you are fluent in these five ideas.
The symbols that combine and compare values — arithmetic, comparison, logical, and assignment.
Every JavaScript journey starts with the fundamentals. Before loops, functions, or frameworks, you need to understand what JavaScript is, how to declare variables, what types values can have, and how to print results to the console.
Whether you are brand new to programming or coming from another language, this module gives you a solid foundation. Each chapter includes interactive visualizations so you can watch values move through memory instead of only reading about them.
Operators are how data actually gets transformed: adding prices, checking if a password matches, deciding whether a user is old enough. Subtle rules like == vs === and short-circuiting with && / || are among the most common sources of real-world bugs, so getting them right early pays off everywhere.
Basic math operations on numbers.
Interactive — change values
Addition
10 + 3 = 13
Subtraction
10 - 3 = 7
Multiplication
10 * 3 = 30
Division
10 / 3 = 3.3333
Modulus
10 % 3 = 1
Exponent
10 ** 3 = 1000
// Increment & Decrement let count = 5; count++; // 6 (post-increment) count--; // 5 (post-decrement) ++count; // 6 (pre-increment) // Unary operators let x = "5"; console.log(+x); // 5 (converts to number) console.log(-x); // -5
💡 String + Number: "5" + 3 = "53" (concatenation, not addition). Use Number() or + to convert first.
Store and update values in variables.
| Operator | Example | Same As |
|---|---|---|
| = | x = 10 | x = 10 |
| += | x += 5 | x = x + 5 |
| -= | x -= 3 | x = x - 3 |
| *= | x *= 2 | x = x * 2 |
| /= | x /= 4 | x = x / 4 |
| %= | x %= 3 | x = x % 3 |
| **= | x **= 2 | x = x ** 2 |
let score = 0; console.log(score);
Start with score = 0.
Compare values and get true or false.
| Expression | Result | Why |
|---|---|---|
| 5 == "5" | true | Loose: converts types |
| 5 === "5" | false | Strict: different types |
| null == undefined | true | Special case in spec |
| null === undefined | false | Different types |
| NaN === NaN | false | NaN is never equal to anything |
🏆 Always use === (strict equality). It checks both value and type, avoiding confusing type coercion.
Combine conditions with AND, OR, and NOT.
Interactive — toggle values
// Short-circuit evaluation let user = null; let name = user && user.name; // null (stops at falsy) let fallback = name || "Guest"; // "Guest" (finds first truthy) // Nullish coalescing (see next section) let count = 0; let result = count ?? 10; // 0 (only null/undefined trigger ??)
Falsy Values in JavaScript
Everything else is truthy (including "0", "false", [], {}).
Concise conditional expressions.
// Ternary operator: condition ? ifTrue : ifFalse let age = 20; let status = age >= 18 ? "adult" : "minor"; console.log(status);
The ternary operator is a one-line if/else. If the condition is true, return the first value; otherwise the second.
Which operations execute first?
| Priority | Operator | Example |
|---|---|---|
| 1 (highest) | ( ) | (2 + 3) * 4 |
| 2 | ** ++ -- ! | 2**3, !true |
| 3 | * / % | 6 * 2 / 3 |
| 4 | + - | 5 + 3 - 1 |
| 5 | < > <= >= | a > b |
| 6 | == != === !== | a === b |
| 7 | && | a && b |
| 8 | || | a || b |
| 9 | ?? | a ?? b |
| 10 (lowest) | = += -= etc. | x = 5 |
// What does this evaluate to? let result = 2 + 3 * 4 ** 2; // Step 1: 4 ** 2 = 16 // Step 2: 3 * 16 = 48 // Step 3: 2 + 48 = 50 console.log(result);
🏆 Best practice: Use parentheses to make complex expressions readable, even when not strictly necessary.
Test your understanding.
What does 10 % 3 return?
What does this output?
console.log("5" == 5);What does this output?
console.log("5" === 5);What does true && 0 || 'hello' evaluate to?
Common questions about operators.
Test your understanding — 3 questions
What does this expression evaluate to?
console.log(5 + "3");