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.
| Attribute | Description |
|---|---|
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
πΈ 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.
| Attribute | Description |
|---|---|
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
π§ Test Your Knowledge
5 QuestionsProgress: 0 / 5
Keep Going!JS - Console