β‘
EPISODE 01
let Β· const Β· primitive vs object Β· typeof
Variables & Types
Declare variables properly with let and const, understand JavaScript's primitive and object types, and use typeof to inspect values.
JavaScriptletconsttypestypeof
Duration
β± About 1.5 hours
Level
π Beginner
Prerequisite
π― Lessons 1β4
OUTCOME
Pick the right declaration for every value and predict its type
What you'll learn
- 1Choose between let and const (never var)
- 2Distinguish primitives from objects
- 3Use typeof to inspect a value's type
- 4Convert between number, string, and boolean safely
1. let, const, var
javascript
let count = 0; // mutable
const NAME = "Alice"; // immutable binding
var legacy = true; // legacy, do not use
count = 1; // OK
// NAME = "Bob"; // TypeError- const by default β most variables never need to change
- let when you must reassign (loop counters, conditional values)
- var has function scope and hoisting quirks β avoid entirely
2. Primitive Types
| Type | Example | typeof |
|---|---|---|
| number | 42, 3.14, NaN, Infinity | "number" |
| string | "hello", `template` | "string" |
| boolean | true, false | "boolean" |
| undefined | undefined | "undefined" |
| null | null | "object" (a famous bug) |
| bigint | 9007199254740993n | "bigint" |
| symbol | Symbol("id") | "symbol" |
3. Objects
javascript
const user = { name: "Alice", age: 30 };
const nums = [1, 2, 3];
const now = new Date();
typeof user; // "object"
typeof nums; // "object" (arrays are objects)
Array.isArray(nums); // trueπ‘
Use Array.isArray() to detect arrays β typeof returns "object" for them.
4. Type Conversion
javascript
Number("42"); // 42
String(42); // "42"
Boolean(0); // false
Boolean(""); // false
Boolean("hello"); // true
// Coercion gotchas
"5" + 3; // "53" (string concatenation)
"5" - 3; // 2 (numeric subtraction)
"5" == 5; // true (loose equality)
"5" === 5; // false (strict β use this!)Example code / lecture materials
All lecture materials and example code are openly available on GitHub.
View on GitHub β