Chapter 08

JavaScript Data Types

A data type describes the kind of value stored or represented by JavaScript.

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.

Syntax

let name = 'Aman';
let age = 20;
let passed = true;
let value;
let empty = null;

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);

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.

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.

Real-World Use

Understanding data types is important when processing form data, API responses, calculations, and application state.

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.

Try It Yourself →