Data types
string, number, boolean, null, undefined — the five flavours of data.
Step 1
The idea
Not all information is the same kind of thing. "Priya" is a name. 42 is a count. true/false is a yes/no answer. Nothing is... nothing.
JavaScript has five basic kinds of data. Think of them as different types of storage containers — you wouldn't store water in a paper bag or a name in a number slot.
Knowing the type matters because JavaScript behaves differently depending on what kind of data you're working with.
Step 2
See it run
string: Priya
number: 42
boolean: true
null: null
undefined: undefinedconst name = "Priya"; // string — text, always in quotes
const age = 42; // number — any number, no quotes
const isPassed = true; // boolean — only true or false
const score = null; // null — intentionally empty
let address; // undefined — declared but not given a value yet
console.log("string:", name);
console.log("number:", age);
console.log("boolean:", isPassed);
console.log("null:", score);
console.log("undefined:", address);$ node data-types.jsStep 3
Now you try
Change isPassed from true to false and run it again. Then try this line at the bottom:
console.log(typeof name); // "string"
console.log(typeof age); // "number"
console.log(typeof isPassed); // "boolean"typeof is JavaScript's way of telling you what type a value is. You'll use it when debugging.
Step 4
Why a tester cares
Real programs mix all five types together. Here's a small student record — you'll recognise every type in it:
const studentName = "Priya"; // string
const score = 87; // number
const hasPassed = true; // boolean
const medalAwarded = null; // null — not awarded yet
let rank; // undefined — not calculated yet
console.log(`Name: ${studentName}`);
console.log(`Score: ${score}`);
console.log(`Passed: ${hasPassed}`);
console.log(`Medal: ${medalAwarded}`); // null
console.log(`Rank: ${rank}`); // undefined
// typeof tells you what kind of data something is
console.log(typeof studentName); // string
console.log(typeof score); // number
console.log(typeof hasPassed); // boolean$ node student.jsEvery program you write — automation or otherwise — uses these exact types. Knowing them by name makes reading error messages and debugging much faster.
Recap
- 1string = text in quotes. number = any number. boolean = true or false.
- 2null means intentionally empty. undefined means declared but never assigned.
- 3Use typeof to check what type a value is — useful when debugging unexpected behaviour.