Logo
READLEARNKNOWCONNECT
Back to Lessons

    Page

  • - What Are Data Types?
  • - Primitive Data Types
  • - Examples of Primitive Types
  • - Complex Data Types
  • - Checking a Value’s Type
  • - Mini Challenge
  • - Key Takeaway

3. JavaScript Data Types

Level: BeginnerDuration: 14m

What Are Data Types?

Every piece of data in JavaScript has a type. Data types define what kind of value something is and how you can use it in your code.

There are two main categories: *primitive types* (like strings and numbers) and *complex types* (like objects and arrays).

Primitive Data Types

  • `String` — Text data, written inside quotes.
  • `Number` — Numeric data, including decimals.
  • `Boolean` — True or false values.
  • `Undefined` — A variable that has been declared but not assigned a value.
  • `Null` — Represents an intentional 'nothing' value.
  • `Symbol` — A unique and immutable value (used for special cases).
  • `BigInt` — For very large numbers that can’t be represented as regular numbers.

Examples of Primitive Types

javascript
let name = "Ada";       // String
let age = 25;            // Number
let isStudent = true;    // Boolean
let score;               // Undefined
let emptyValue = null;   // Null
let uniqueId = Symbol(); // Symbol
let bigNumber = 123456789012345678901234567890n; // BigInt

Complex Data Types

Complex (or reference) types are collections of values. The two most common are arrays and objects.

javascript
let colors = ["red", "green", "blue"];  // Array
let user = { name: "Ada", age: 25 };     // Object

Arrays use square brackets `[]`, and objects use curly braces `{}`. Arrays hold ordered lists, while objects store data in key-value pairs.

Checking a Value’s Type

You can use the `typeof` operator to find out what type of value something is.

javascript
console.log(typeof "Hello");  // string
console.log(typeof 42);        // number
console.log(typeof true);      // boolean
console.log(typeof [1,2,3]);   // object (arrays are special objects)
console.log(typeof null);      // object (this is actually a long-standing bug in JS!)

Mini Challenge

Create a few variables using different data types — at least one string, number, array, and object. Then log each one with `typeof` to see what JavaScript reports.

javascript
// Example:
const city = "Lagos";
const population = 15000000;
const isBusy = true;
const landmarks = ["Lekki Bridge", "National Theatre"];
const info = { country: "Nigeria", region: "West Africa" };

console.log(typeof city);
console.log(typeof population);
console.log(typeof landmarks);
console.log(typeof info);

Key Takeaway

JavaScript handles many data types automatically, but knowing how they work helps you debug faster and write cleaner code. Remember: everything in JS has a type — even `null` and arrays!

MDN Docs: JavaScript Data Types