Nearby lessons

5 of 40

🔢 JavaScript Data Types

📌 What are JavaScript Data Types?

JavaScript provides different types of values. These are classified as:

JavaScript is a dynamic type language, which means you don't need to specify the type of variable explicitly.

📝 A variable declared with var can hold any data type like numbers, strings, etc.

Example:

var a = 40;        // holding number
var b = "Rahul";   // holding string

📋 Types of Data

  • 🧱 Primitive Data Types
  • 🧭 Non-Primitive (Reference) Data Types

🔹 Primitive Data Types

These are the most basic data types in JavaScript. They hold single, immutable (unchangeable) values. They are not objects and have no methods.

  • Characteristics:
  • 🧱 Stored directly in the variable.
  • 🧭 Immutable (can't be changed directly).
  • 📜 Fast and simple.
AttributeDescription
String📜 Represents sequence of characters. Example: "hello"
Number🔢 Represents numeric values. Example: 100
Boolean✅ Represents true or false
Undefined❓ Represents a variable with no assigned value
Null🚫 Represents no value or non-existent
Example03
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🔸 Non-Primitive (Reference) Data Types

These are complex data types. They store references (addresses in memory) to the actual data.
  • Characteristics:
  • 🧱 Can hold multiple values.
  • 🧭 Mutable (you can change their contents).
  • 📜 Slower to access compared to primitive types.
AttributeDescription
Object📦 Used to store keyed collections and more complex entities
Array📚 Represents a group of similar or different values
RegExp🔍 Represents regular expressions for pattern matching
Example05
Code Cell
Loading Editor...
✏️ You can edit this code — click Run to refresh the preview.
Output

🧠 Test Your Knowledge

5 Questions
Progress: 0 / 5