Data Types
Learn what data types are and how JavaScript stores different kinds of values.
What is a Data Type?
A data type tells us what kind of value is being used in a JavaScript program.
For example, a student name is text, marks are numbers, and a result status can be true or false.
JavaScript data types classification.
JavaScript Data Types
JavaScript has eight standard data types: seven primitive types and one Object type.
Primitive Data Types
String
Used for text values.
Number
Used for numeric values.
BigInt
Used for very large integer values.
Boolean
Represents true or false.
Undefined
Represents a value that has not been assigned.
Null
Represents an intentional absence of a value.
Symbol
Represents a unique primitive value.
Object
Used to store collections of related properties and values.
Example 1: Common Data Types
Here we create different variables and store different types of values.
const studentName = "Neha";
const marks = 90;
const isEnrolled = true;
console.log("Welcome to CIIT Training Institute ❤️🧑🎓.....!");
console.log("Student:", studentName);
console.log("Marks:", marks);
console.log("Enrolled:", isEnrolled);
Output
Student: Neha
Marks: 90
Enrolled: true
Checking Data Type with typeof
The typeof operator is used to check the type of a value.
Example 2: typeof Operator
const student = "Rohit";
const score = 85;
const selected = true;
console.log("Student:", student);
console.log("Type:", typeof student);
console.log("Score:", score);
console.log("Type:", typeof score);
console.log("Selected:", selected);
console.log("Type:", typeof selected);
console.log("CIIT Training Institute ❤️.....!");
Output
Type: string
Score: 85
Type: number
Selected: true
Type: boolean
CIIT Training Institute ❤️.....!
undefined and null
undefined usually means that a value has not been assigned, while null is commonly used to represent an intentional empty value.
Example 3: undefined and null
let course;
const trainer = null;
console.log("Course:", course);
console.log("Course Type:", typeof course);
console.log("Trainer:", trainer);
console.log("Trainer Type:", typeof trainer);
console.log("Learning at CIIT Training Institute ❤️🧑🎓.....!");
Output
Course Type: undefined
Trainer: null
Trainer Type: object
Learning at CIIT Training Institute ❤️🧑🎓.....!
Important Point
JavaScript has seven primitive data types: String, Number, BigInt, Boolean, Undefined, Null, and Symbol. Object is the eighth standard data type.
Summary
Data types describe the kind of value used by a JavaScript program. JavaScript has seven primitive data types and the Object type. The typeof operator can be used to check the type of a value.