Data Types in JavaScript

Javascript 8 min min read Updated: Mar 09, 2026 Beginner
Data Types in JavaScript
Beginner Topic 4 of 15

Data Types in JavaScript

In JavaScript, data types define the type of value that a variable can store. When we create variables in a program, those variables hold different kinds of data such as numbers, text, or logical values. JavaScript uses data types to understand how the stored data should be processed.

Understanding data types is very important because they help developers perform correct operations on data. For example, adding two numbers is different from combining two text strings.

What are Data Types?

A data type describes the type of value stored in a variable. JavaScript automatically determines the type of data when a value is assigned to a variable. This behavior is called dynamic typing.

javascript let age = 25; let name = "John";

In the example above, JavaScript automatically understands that 25 is a number and "John" is a string.

Types of Data Types in JavaScript

JavaScript data types are generally divided into two main categories:

  • Primitive Data Types
  • Non-Primitive (Reference) Data Types

Primitive Data Types

Primitive data types store single values and are the most basic types of data in JavaScript.

1. String

A string represents textual data. Strings are written inside single quotes (' '), double quotes (" "), or backticks.

javascript let city = "Delhi"; console.log(city);

Strings are commonly used for names, messages, or any textual information.

2. Number

The number data type represents numeric values. JavaScript uses the same type for both integers and decimal numbers.

javascript let price = 100; let discount = 12.5; console.log(price); console.log(discount);

3. Boolean

The boolean data type represents logical values. It can only have two possible values: true or false.

javascript let isLoggedIn = true; console.log(isLoggedIn);

Booleans are widely used in conditions and decision-making statements.

4. Undefined

A variable that has been declared but not assigned any value automatically has the undefined data type.

javascript let score; console.log(score);

5. Null

The null data type represents an intentional absence of value. It means the variable is empty.

javascript let result = null; console.log(result);

6. BigInt

BigInt is used to store very large integers that exceed the limit of the normal number data type.

javascript let bigNumber = 123456789012345678901234567890n; console.log(bigNumber);

7. Symbol

The Symbol data type is used to create unique identifiers. It is mostly used in advanced JavaScript programming.

javascript let id = Symbol("userID"); console.log(id);

Non-Primitive Data Types

Non-primitive data types are more complex and can store collections of values or more detailed entities.

1. Object

Objects store data in key-value pairs. They are widely used in JavaScript to represent real-world entities.

javascript let student = { name: "Rahul", age: 20, course: "Computer Science" }; console.log(student.name);

2. Array

Arrays are used to store multiple values in a single variable.

javascript let fruits = ["Apple", "Mango", "Banana"]; console.log(fruits[0]);

Checking Data Type Using typeof

JavaScript provides the typeof operator to check the type of a variable.

javascript let name = "Alex"; let age = 30; console.log(typeof name); console.log(typeof age);

Output:

output string number

Conclusion

Data types are fundamental to understanding how JavaScript works. They define the kind of data stored in variables and determine how operations are performed on that data.

JavaScript includes several primitive data types such as string, number, boolean, undefined, null, bigint, and symbol. It also supports complex non-primitive types such as objects and arrays.

A clear understanding of data types helps developers write efficient and error-free programs. In the next tutorial, we will learn about JavaScript Operators and how they are used to perform operations on variables and values.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators