A data type tells the computer what kind of data a variable stores and what operations can be done with it.
For example:
10 → number
"Hello" → text
true → boolean
In simple words, a data type defines what kind of value a variable can hold.
There are Two types of Data types used in JavaScript:
- Primitive Data Type
- Non- Primitive Data Type
Primitive Data Type:
It can hold only single value. For example:
let Name= "Tony"
A memory will be created on the key "Name" and the value "Tony" will be stored. The Primitive Data Types are immutable.
If I give another value in the same key "Name" and give the value "Parthipan"
Name="Parthipan"
A new memory will be created and the value "Parthipan" will be stored.
Non- Primitive Data Type
Unlike Primitive,It can Store multiple values. It is called an Object. The object contains the Arrays and Functions.
let userDetails = {
name: "Mark Tony",
email: "tony@gmail.com",
location: "chennai",
welcome: function (a,b){
return a+b;
},
};
Various Primitive data types:
- String: A string is a sequence of text or characters written inside single quotes (' ') or double quotes (" ").
- Number: A number represents both integer and decimal (floating-point) values.
- BigInt: BigInt is used to represent very large integers accurately beyond the safe range of the Number type.
- Boolean: A Boolean represents a logical value that can be either true or false.
- Null: Null represents the intentional absence of a value.
- Undefined: Undefined means a variable has been declared but no value has been assigned to it.
- Symbol: A Symbol is a unique and immutable primitive value, commonly used to create unique object property keys.
Easy way to remember
- String → Text
- Number → Numbers
- BigInt → Very large integers
- Boolean → True/False
- Null → Intentional empty value
- Undefined → No value assigned
- Symbol → Unique value
Top comments (0)