Chapter 08
JavaScript Data Types
A data type describes the kind of value stored or represented by JavaScript.
01 • Learn
What is JavaScript Data Types?
- JavaScript has primitive values and objects.
- Common primitive types include string, number, boolean, undefined, null, bigint, and symbol.
- Objects can represent more complex data structures.
- JavaScript is dynamically typed, so a variable's value can determine its type at runtime.
02 • Syntax
Syntax
let name = 'Aman'; let age = 20; let passed = true; let value; let empty = null;
03 • Example
Example
Try understanding this code before running it.
let name = 'Aman'; let age = 20; let passed = true; let city; let result = null; console.log(typeof name); console.log(typeof age); console.log(typeof passed); console.log(typeof city);
04 • Remember
Important Points
- A string represents text.
- A number represents numeric values.
- A Boolean represents true or false.
- undefined and null have different meanings.
- The typeof operator can help inspect a value's type.
05 • Avoid
Common Mistakes
- Assuming null and undefined always mean exactly the same thing.
- Ignoring type conversion when combining user input with numbers.
- Using typeof without understanding its result.
06 • Practical
Real-World Use
Understanding data types is important when processing form data, API responses, calculations, and application state.
07 • Practice
Practice Exercise
Practice: Data Types
Create a string, number, Boolean, and undefined variable. Use typeof to check each data type.
Ready to write code?
Open the JavaScript editor and run your code with live output.