By the end of this lesson, learners will:
undefined
and null
typeof
operator to check data typesEvery piece of data in a JavaScript program has a type.
A data type tells JavaScript:
📦 Think of it like different containers:
JavaScript has two major categories of data types:
These are the most basic values in JavaScript. They are immutable (cannot be changed).
Type | Example | Description |
---|---|---|
String | "hello" | Text values |
Number | 42 , 3.14 | Whole and decimal numbers |
Boolean | true , false | Logical values |
Undefined | let x; | Declared but no value assigned |
Null | let x = null; | Intentional empty value |
BigInt | 12345678901234567890n | Very large integers |
Symbol | Symbol("id") | Unique identifiers (advanced) |
These store collections of data or more complex entities.
Type | Example | Description |
---|---|---|
Object | { name: "Alice", age: 25 } | Key-value pairs |
Array | [1, 2, 3] | Ordered list of items |
Function | function greet() {} | Reusable blocks of code |
We’ll explore objects, arrays, and functions in later modules.
'
), double ("
), or template literals (`
).📌 Example:
let name = "Alice";
let greeting = `Hello, ${name}!`; // using template literals
📌 Example:
let age = 30;
let price = 19.99;
true
or false
.📌 Example:
let isStudent = true;
let passed = false;
📌 Example:
let x;
console.log(x); // undefined
📌 Example:
let user = null;
🔍 undefined
means “not assigned.”
🔍 null
means “intentionally empty.”
n
to the end of a number.📌 Example:
let big = 123456789012345678901234567890n;
📌 Example:
let id = Symbol("id");
typeof
OperatorUse the typeof
keyword to check a variable’s type:
📌 Example:
let name = "Alice";
console.log(typeof name); // "string"
let age = 30;
console.log(typeof age); // "number"
let isOnline = true;
console.log(typeof isOnline); // "boolean"
let city = "Berlin"; // String
let temperature = 22.5; // Number
let isSunny = true; // Boolean
let nothingHere = null; // Null
let notSet; // Undefined
let largeNumber = 9007199254740991n; // BigInt
Type | Keyword | Example | typeof result |
---|---|---|---|
String | "..." | "Hello" | "string" |
Number | Any num | 42 , 3.14 | "number" |
Boolean | true/false | true | "boolean" |
Undefined | – | let x; | "undefined" |
Null | null | let x = null; | "object" (quirk) |
BigInt | n | 123n | "bigint" |
Symbol | Symbol() | Symbol("id") | "symbol" |