Master JavaScript Programming From Scratch

Clear, interactive, and structured JavaScript lessons designed for absolute beginners.

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

JavaScript data types classification.

JavaScript Data Types

JavaScript has eight standard data types: seven primitive types and one Object type.

Data Type Classification
Primitive Types
+
Object

Primitive Data Types

String

Used for text values.

"JavaScript"
Number

Used for numeric values.

100
BigInt

Used for very large integer values.

9007199254740993n
Boolean

Represents true or false.

true
Undefined

Represents a value that has not been assigned.

let value;
Null

Represents an intentional absence of a value.

null
Symbol

Represents a unique primitive value.

Symbol("id")
Object

Used to store collections of related properties and values.

{ name: "Omkar" }

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

Welcome to CIIT Training Institute ❤️🧑‍🎓.....!
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

Student: Rohit
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: undefined
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.