

Lesson 01 · 10 min
Values and variables
Where to put data and how to tell what exactly you put there.
10 minLesson 1 of 10Practice includedAsk AI on any point
A program stores data in variables. There are two declarations: const and let. Don't use the old var — it's visible outside the block it's declared in and causes bugs out of nowhere.
const forbids reassigning the name, but it doesn't forbid changing the contents of an object or array. These are different operations: one changes what the name points to, the other changes what's inside.
What kinds of values there are
number— integers and fractions alike. There's no separate integer type.string— text:"a",'b'or in backticks.boolean— exactly two values:trueandfalse.null— empty, and you put it there.undefined— there's no value: a variable without assignment, a missing property, a function withoutreturn.object— everything compound: objects, arrays, dates.
Two answers you just have to memorize. An array is an object; you can tell it apart with Array.isArray(value). And typeof null === "object" is a bug from the first version of the language that was never fixed for compatibility. Check for null directly: value === null. Everything the operator returns is listed in MDN · typeof.
A variable name consists of letters, digits, _ and $ and doesn't start with a digit. Case matters: total and Total are different names. Name things by meaning: itemsCount reads well, x doesn't. Declarations are covered in detail in Grammar and types.
- MDN · const: why the name can't be reassigned
- MDN · let: block scope
- MDN · typeof: the full list of the operator's answers
- MDN · Grammar and types: declarations, literals, type coercion
Check
Lock it in before you move on
1. What does
typeof nullreturn?2.
const cart = []; cart.push(1)— what happens?3. A function without
returnwas called. What did it return?4. When do you use
letinstead ofconst?