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
Code Example
PREVIEW READY
Loading Editor...
Live Preview

πŸ”Έ 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
Code Example
PREVIEW READY
Loading Editor...
Live Preview

🧠 Test Your Knowledge

5 Questions

Progress: 0 / 5
Keep Going!JS - Console