What is Datatype?
- Datatype is used to tell us that what kind of data is stored inside a variable.
Example:
let name = "Raksha"; // String
let age = 21; // Number
let isStudent = true; // Boolean
-
There are two types of Datatypes:
1. Primitive Datatype 2. Non-Primitive Datatype
Primitive Datatype:
- Primitive Datatypes are used to store a single value.
- Primitive Datatypes in JavaScript are immutable in nature.
- Immutable means their value can't be changed after creation.
Types of Primitive Datatypes:
1. Number
2. String
3. BigInt
4. Boolean
5. Undefined
6. Null
7. Symbol
Number:
-
Numberdatatype is used to store the numeric values including both integer and decimals values.
Example:
let age = 21;
let marks = 85.5;
let temperature = -10;
Output:
console.log(typeof age); // number
console.log(typeof marks); // number
console.log(typeof temperature); // number
String:
-
stringdatatype is used to store sequence of characters as well as single characters.
Example:
let name="Raksha";
let grade="O";
Output:
console.log(typeof name); // string
console.log(typeof grade); // string
Boolean:
-
booleandatatype is used to store true or false values.
Example:
let isStudent = true;
let isLoggedIn = false;
Output:
console.log(typeof isStudent); // boolean
console.log(typeof isLoggedIn); // boolean
BigInt:
-
bigintis used to store very large integer values. It is created by adding n at the end of an integer.
Example:
int largeNumber=123456789905322324456667864433n;
Output:
console.log(typeof largeNumber); // bigint
Undefined:
-
undefineddatatype is used represents a variable that has been declared but has not been assigned a value.
Example:
let animal;
Output:
console.log(typeof animal); // undefined
Null:
-
nulldatatype is used to intentionally make the variable as empty.
Example:
let user = null;
Output:
console.log(user); // null
Top comments (2)
Great work Rakshambika
Thank You