Data types tell what kind of value a variable stores in JavaScript.
- Primitive types store a single value.
- Non-primitive types can store multiple values.
Primitive types:
1. String:
let name = "Mahendra";2. Number:
let age = 25;3. Boolean:
let isLogin = true;4. Undefined:
let city;5. Null:
let data = null;6. BigInt:
let bigNum = 12345678901234567890n;7. Symbol:
let id = Symbol("id");Non-primitive types:
1. Object:
let person = {
name: "Raj",
age: 25
};2. Array:
let colors = ["Red", "Blue", "Green"];JavaScript typeof Operator
The typeof operator is used to check the data type of a variable or value in JavaScript.
let name = "Mahendra";
console.log(typeof name);Output:
string