Manuals / JavaScript / Chapter 2

A · Fundamentals · beginner · Week 1 · Chapter 2 of 14

Values, variables & control flow

JavaScript has eight types (seven primitives + object). let and const replace var. Control flow — if/else, loops, switch — is how programs make decisions. Master ===, truthy/falsy, and template literals before moving on.

Path progress
9%

Step 1 of 5

Types and typeof

Primitives: string, number, boolean, null, undefined, symbol, bigint. Everything else is an object (including arrays and functions). typeof null returns "object" — a famous bug never fixed for compatibility.

Types and typeofDrag stickies · tap for tips
Study mapDrag stickies · tap for tipsKeep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Assert the UIdrag · tap →Retry wiselydrag · tap →Seed datadrag · tap →Close the loopdrag · tap →Keep it shortdrag · tap →Name the waitdrag · tap →Scope locatorsdrag · tap →Trace when stuckdrag · tap →One browser firstdrag · tap →Isolate statedrag · tap →Pathwise hackdrag · tap →Types and typeofdrag · tap →Try thisdrag · tap →Follow the dashed drag · tap →

Example

typeof "hello"   // "string"
typeof 42        // "number"
typeof true      // "boolean"
typeof undefined // "undefined"
typeof null      // "object" (historical quirk)
typeof {}        // "object"
typeof []        // "object"
typeof (() => {}) // "function"

Do this now

In the console, test typeof on 10 different values. Write a comment explaining null and undefined.

Was this step clear?
Chapter learning outcomes
  • Primitives vs objects
  • let/const and block scope
  • if/else, for, while
  • === vs ==
  • Template literals

Clear these before you leave

Side quest

FizzBuzz

Print 1–20. Multiples of 3 → "Fizz", 5 → "Buzz", both → "FizzBuzz". Use a loop and if/else.