CoursePart 1 — JavaScript for PlaywrightLesson 1.4
Lesson 1.4Part 1 — JavaScript for Playwright

Data types

string, number, boolean, null, undefined — the five flavours of data.

Lesson 1.4of 24
Next

Step 1

The idea

01

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

02
Output
string: Priya
number: 42
boolean: true
null: null
undefined: undefined
data-types.js
const 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);
Terminal
$ node data-types.js

Step 3

Now you try

03

Change isPassed from true to false and run it again. Then try this line at the bottom:

js
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

04

Real programs mix all five types together. Here's a small student record — you'll recognise every type in it:

student.js
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
Terminal
$ node student.js

Every program you write — automation or otherwise — uses these exact types. Knowing them by name makes reading error messages and debugging much faster.

Recap

3 key points
  • 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.