Now that you know how to create variables using var, let, and const, here's the next question:
What kind of data are we storing inside those variables?
For example,
let name = "Alex";
let age = 20;
let isLoggedIn = true;
These three variables don't store the same kind of value.
"Alex"is text.20is a number.trueis either true or false.
JavaScript needs to know what type of data each value is. That's where Data Types come in.
As shown in the slide,
Every value in JavaScript belongs to a specific data type.
Think of a warehouse that stores different kinds of items. Books go on one shelf, clothes on another, electronics on another. Even though everything is stored in the same warehouse, each item belongs to a different category.
JavaScript works in the same way. Every value has its own category, which we call a data type.
What is a Data Type?
A Data Type tells JavaScript what kind of value it is dealing with.
For example,
let language = "JavaScript";
Here,
"JavaScript"
is a String because it is text.
Now look at this.
let marks = 95;
Here,
95
is a Number.
And this one,
let passed = true;
stores a Boolean value.
Every value has a type.
That helps JavaScript understand how that value should be stored and what operations can be performed on it.
JavaScript Data Types
The slide divides data types into two major categories.
Data Types
│
├── Primitive Types
│
└── Non-Primitive Types
Let's understand both one by one.
Primitive Types
The first section of the slide introduces Primitive Types.
It says:
Stores a single value.
Think of a primitive value like a single gemstone.
It represents only one value and nothing more.
JavaScript has 7 Primitive Data Types.
1. String
A String represents text.
The slide uses this example.
"Hello"
Strings are always written inside
Double quotes
" "Single quotes
' 'Backticks
Example
let name = "Alex";
Here,
"Alex"
is a String.
More examples
"JavaScript"
"Apple"
"India"
Anything that is text is considered a String.
2. Number
Numbers represent numeric values.
The slide shows
25
Numbers can be
10
20
99
3.14
-15
0
Unlike some programming languages, JavaScript uses a single Number type for both integers and decimal numbers.
Example
let age = 20;
let price = 499.99;
Both are Numbers.
3. Boolean
A Boolean stores only two possible values.
The slide shows
true
There are only two Boolean values.
true
false
Booleans are mostly used for decisions.
Example
let isLoggedIn = true;
Later,
if (isLoggedIn) {
console.log("Welcome");
}
JavaScript checks whether the value is true or false.
4. Null
The slide shows
null
null means
"There is intentionally no value."
Imagine you're waiting for your food order.
The restaurant says,
"We haven't assigned a delivery person yet."
That is similar to null.
Example
let selectedUser = null;
Currently,
there is no selected user.
Later,
selectedUser = "Alex";
Now it has a value.
5. Undefined
The slide also includes
undefined
Many beginners confuse null and undefined.
They're different.
Example
let city;
Since no value is assigned,
JavaScript automatically gives it
undefined
So,
undefinedmeans no value assigned yet.nullmeans we intentionally assigned an empty value.
6. Symbol
The slide shows
Symbol("id")
Symbol creates a unique value.
Even if two Symbols have the same description,
they are still different.
Example
const id1 = Symbol("id");
const id2 = Symbol("id");
Now,
id1 === id2
returns
false
Symbols are commonly used when creating unique object properties or working with libraries.
As a beginner, you won't use them very often, but it's good to know they exist.
7. BigInt
The slide also introduces
123456789n
Normally, JavaScript Numbers have a limit on how large they can safely become.
For extremely large integers,
JavaScript provides BigInt.
Example
let population = 12345678901234567890n;
Notice the n at the end.
That tells JavaScript this is a BigInt instead of a normal Number.
You'll mostly encounter BigInt when working with very large calculations or certain backend applications.
Non-Primitive Types
The next section of the slide talks about Non-Primitive Types.
Unlike primitive values,
these can hold multiple values or even behavior.
The slide includes three common examples.
Object
Array
Function
Let's understand each one.
Object
The slide shows
{
name: "Alex",
age: 20
}
An Object stores information using key-value pairs.
Think of an ID card.
It stores
Name
Age
Address
Phone Number
All related information is grouped together.
Example
let student = {
name: "Alex",
age: 20
};
Instead of storing separate variables,
everything is stored inside one object.
Array
The slide uses
[
"Apple",
"Banana",
"Mango"
]
An Array stores multiple values in order.
Think of a shopping basket.
Instead of carrying one fruit,
it carries many.
Example
let fruits = ["Apple", "Banana", "Mango"];
Now all fruits are stored together.
Arrays are one of the most commonly used data types in JavaScript.
Function
The slide shows
function greet() {
console.log("Hi");
}
A Function stores behavior.
Instead of storing data,
it stores instructions.
Think of a coffee machine.
Press the button,
and it performs a task.
Similarly,
calling a function makes JavaScript execute its code.
Example
function greet() {
console.log("Hello");
}
Later,
greet();
Output
Hello
Primitive vs Non-Primitive
The slide explains this beautifully.
Primitive values are like a single gem.
Each variable gets its own copy.
Non-Primitive values are like a shared storage box.
Instead of copying everything,
JavaScript shares the reference.
Let's see the difference.
Primitive
let a = 10;
let b = a;
b = 20;
Now,
a = 10
b = 20
Changing b doesn't affect a.
Each variable has its own copy.
Non-Primitive
let person1 = {
name: "Alex"
};
let person2 = person1;
person2.name = "John";
Now,
person1.name
also becomes
John
Why?
Because both variables point to the same object in memory.
This behavior is called Copy by Reference.
The slide summarizes it perfectly.
Primitive | Non-Primitive |
|---|---|
Copy by Value | Copy by Reference |
The typeof Operator
Sometimes we don't know the data type of a value.
JavaScript provides the typeof operator to check it.
The slide shows several examples.
typeof "Hello"
returns
"string"
typeof 25
returns
"number"
typeof true
returns
"boolean"
typeof undefined
returns
"undefined"
typeof {}
returns
"object"
typeof function(){}
returns
"function"
Notice something interesting.
Although functions are technically objects in JavaScript, typeof returns "function" because JavaScript gives them a special classification.
Special Cases
The slide also highlights two famous JavaScript quirks that surprise almost every beginner.
Why is typeof [] "object"?
The slide shows
typeof []
Output
"object"
Even though an Array feels like its own type,
JavaScript internally treats arrays as a special kind of object.
To specifically check whether something is an array, use:
Array.isArray([])
This returns
true
Why is typeof null "object"?
The slide also shows
typeof null
Output
"object"
This confuses almost everyone!
Logically, null isn't an object.
So why does JavaScript return "object"?
The answer is simple:
It's a historical bug from the early days of JavaScript. By the time developers realized it, changing the behavior would have broken millions of existing websites. So the language kept it for backward compatibility.
It's one of JavaScript's most famous quirks, and interviewers sometimes ask about it.
When Should You Use Which Data Type?
Here's a simple guide.
Use String for text like names, emails, or messages.
Use Number for ages, prices, marks, or counts.
Use Boolean for true/false conditions such as login status.
Use Null when you intentionally want to represent "no value."
Use Undefined when a variable hasn't been assigned a value yet.
Use Object to group related information together.
Use Array to store a list of values.
Use Function to store reusable logic or behavior.
Quick Revision
Topic | Remember |
|---|---|
Data Type | Defines what kind of value a variable stores. |
Primitive Types | String, Number, Boolean, Null, Undefined, Symbol, BigInt. |
Non-Primitive Types | Object, Array, Function. |
String | Stores text inside quotes. |
Number | Stores integers and decimal numbers. |
Boolean | Only |
Null | Intentionally empty value. |
Undefined | Variable declared but not assigned a value. |
Symbol | Creates unique identifiers. |
BigInt | Stores very large integers. |
Primitive Copy | Copy by Value (independent copies). |
Non-Primitive Copy | Copy by Reference (shared reference). |
| Returns the data type as a string. |
Special Cases |
|
