Data Types
Every value in JavaScript has a type. The basic types are: String (text, like "Ali"), Number (like 16 or 3.14 JavaScript doesn't separate whole numbers from decimals the way some languages do), Boolean (true or false), undefined (a variable that's been declared but has no value yet), and null (a deliberate "no value" set on purpose). You can check a value's type with the typeof operator: typeof "Ali" returns "string", typeof 16 returns "number", typeof true returns "boolean". JavaScript is dynamically typed, meaning a variable isn't locked to one type forever let x = 5; x = "now text"; is legal, though generally it's clearer code to keep a variable's purpose (and therefore its type) consistent. Later topics cover two more important types: Array (an ordered list of values) and Object (a collection of named values) both deserve their own dedicated topics because of how central they are to real JavaScript.
Why this matters
- ·Knowing a value's type helps you predict how it will behave in comparisons and calculations.
- ·typeof is a quick, built-in way to check what kind of value you're actually working with.
- ·Understanding undefined vs null avoids confusing 'no value' bugs.
Common mistakes
- ·"5" + 5 produces "55" (text joining), not 10 mixing types in an operation doesn't always do what you'd expect.
- ·undefined and null look similar but mean different things: one is accidental, one is intentional.
- ·JavaScript's flexible typing can hide real bugs if you're not paying attention to what type a variable actually holds.
Frequently asked questions
A text label describing the type of a value, such as "string", "number", or "boolean".
Practice questions
Question 1
Create one variable of each type (string, number, boolean) and display each with typeof.
Question 2
Use typeof to check the type of the value 3.14, and display the result.
Quick check
Just for this topic answer honestly, then check yourself.
1 / 3
