JavaScript Data Types: Primitive and Object Types Explained

JavaScript works with different kinds of values.

A person’s name is text. A product price is a number. A login status may be either true or false. A product can contain several related values inside one object.

JavaScript calls these different kinds of values data types.

Understanding JavaScript data types helps you know what a value represents, what operations you can perform on it, and why some values behave differently from others.

Course Home: JavaScript Tutorial for Beginners
Previous Lesson: JavaScript Variables: let, const and var
Next Lesson: JavaScript Operators Explained for Beginners

Quick Answer

JavaScript has several important data types.

Common primitive types include:

  • String
  • Number
  • Boolean
  • Undefined
  • Null
  • BigInt
  • Symbol

JavaScript also has the object type.

For example:

const name = "Riya";
const age = 25;
const loggedIn = true;

Here:

  • "Riya" is a string.
  • 25 is a number.
  • true is a boolean.

You can check many values with the typeof operator:

console.log(typeof name);
console.log(typeof age);
console.log(typeof loggedIn);

Output:

string
number
boolean

What Is a Data Type in JavaScript?

A data type tells JavaScript what kind of value it is working with.

For example:

const productName = "Laptop";
const price = 50000;
const inStock = true;

These values look different because they represent different things.

"Laptop" is text.

50000 is a number.

true is a boolean value.

Knowing the type matters because JavaScript can perform different operations on different values.

For example, numbers can be added:

const price = 500;
const shipping = 100;

console.log(price + shipping);

Output:

600

Strings can be combined:

const firstName = "Riya";
const lastName = "Sharma";

console.log(`${firstName} ${lastName}`);

Output:

Riya Sharma

Primitive and Object Data Types

A useful beginner distinction is between primitive values and objects.

Primitive JavaScript types include:

  • String
  • Number
  • Boolean
  • Undefined
  • Null
  • BigInt
  • Symbol

Objects are used for more complex collections of related information.

For example:

const product = {
    name: "Laptop",
    price: 50000,
    inStock: true
};

You will learn objects in detail later in the JavaScript Objects tutorial.

JavaScript String

A string stores text.

Strings can use:

"double quotes"

or:

'single quotes'

Modern JavaScript also supports template literals using backticks:

`template literal`

Example:

const name = "Amit";

console.log(name);

Output:

Amit

Real Website Example

A website may store:

const productName = "Wireless Keyboard";
const customerName = "Riya";
const pageTitle = "Contact Us";

All three are strings because they contain text.

Combining Strings

You can combine text using template literals:

const firstName = "Riya";
const city = "Delhi";

const message = `${firstName} lives in ${city}`;

console.log(message);

Output:

Riya lives in Delhi

Template literals are especially useful when a sentence contains variable values.

You will explore strings more deeply in a dedicated JavaScript Strings lesson later.

JavaScript Number

JavaScript uses the number type for ordinary numbers.

Examples:

const age = 25;
const price = 499.99;
const quantity = 3;

You can perform calculations:

const price = 500;
const quantity = 3;

const total = price * quantity;

console.log(total);

Output:

1500

Numbers are commonly used for:

  • Prices
  • Quantities
  • Scores
  • Ages
  • Percentages
  • Measurements
  • Calculations

You will work with numbers extensively in the JavaScript Operators tutorial.

Integers and Decimal Numbers

Both of these use the same JavaScript number type:

const quantity = 5;
const price = 49.99;

JavaScript does not use separate everyday types such as int and float in the same way some other languages do.

Check them:

console.log(typeof quantity);
console.log(typeof price);

Output:

number
number

JavaScript Boolean

A boolean has only two possible values:

true
false

For example:

const loggedIn = true;
const menuOpen = false;

Booleans are useful when your program needs a yes-or-no state.

A website may store:

const inStock = true;
const emailVerified = false;
const darkModeEnabled = true;

Later, conditions can use these values:

const inStock = true;

if (inStock) {
    console.log("Product is available");
}

You will learn conditions in the JavaScript if else tutorial.

JavaScript undefined

A variable can exist without having an assigned value.

For example:

let userName;

console.log(userName);

Output:

undefined

JavaScript uses undefined when a value has not been assigned.

Check its type:

let userName;

console.log(typeof userName);

Output:

undefined

Real Example

Imagine your program expects a delivery address, but the user has not entered one yet:

let deliveryAddress;

At that point, its value is undefined.

JavaScript null

null is normally used when you intentionally want a value to represent no value or empty.

Example:

const selectedProduct = null;

This may mean:

No product has been selected yet.

Another example:

let activeUser = null;

Your application may later assign a user object after login.

null vs undefined

These two values often confuse beginners.

A simple way to think about them is:

undefined

The value has not been assigned.

let city;

null

You intentionally set the value to empty.

let selectedProduct = null;

They are not the same value.

console.log(null === undefined);

Output:

false

Using strict equality with === is important. You will learn more about comparisons in the JavaScript Comparison Operators tutorial.

The Strange typeof null Result

Try:

console.log(typeof null);

JavaScript returns:

object

This is a long-standing behavior in JavaScript.

It does not mean that null should be treated like a normal object.

For beginners, remember:

null represents an intentionally empty value, even though typeof null returns "object".

JavaScript BigInt

Normal JavaScript numbers work for most website calculations.

JavaScript also provides BigInt for integers larger than the safe range of ordinary numbers.

A BigInt can be written with n:

const largeNumber = 9007199254740993n;

console.log(typeof largeNumber);

Output:

bigint

Most beginners will not need BigInt frequently.

It is still useful to know that the type exists.

JavaScript Symbol

Symbol creates unique values.

Example:

const id = Symbol("id");

console.log(typeof id);

Output:

symbol

Symbols are more advanced than strings, numbers and booleans.

As a beginner, you only need to recognize Symbol as one of JavaScript’s primitive data types.

You can study its practical uses later.

JavaScript Objects

Objects store related information together.

For example:

const product = {
    name: "Laptop",
    price: 50000,
    inStock: true
};

Instead of creating three unrelated variables, the product object keeps the information together.

You can access a property:

console.log(product.name);

Output:

Laptop

Objects are extremely important in modern JavaScript, API data, TypeScript and Angular.

You will study them properly in the JavaScript Objects tutorial.

Are Arrays a JavaScript Data Type?

Arrays are special objects used to store ordered collections.

Example:

const products = ["Laptop", "Phone", "Tablet"];

You can access the first item:

console.log(products[0]);

Output:

Laptop

If you check an array with typeof:

console.log(typeof products);

the result is:

object

To specifically test whether a value is an array, use:

console.log(Array.isArray(products));

Output:

true

You will learn indexing and array methods in the JavaScript Arrays tutorial.

What Does typeof Do?

The typeof operator tells you the type of many JavaScript values.

Example:

const name = "Amit";
const age = 25;
const loggedIn = true;

console.log(typeof name);
console.log(typeof age);
console.log(typeof loggedIn);

Output:

string
number
boolean

More examples:

console.log(typeof undefined);
console.log(typeof 100n);
console.log(typeof Symbol("id"));

Output:

undefined
bigint
symbol

typeof Examples Table

ValueExampletypeof Result
String"Hello""string"
Number25"number"
Booleantrue"boolean"
Undefinedundefined"undefined"
Nullnull"object"
BigInt10n"bigint"
SymbolSymbol()"symbol"
Object{}"object"
Array[]"object"
Functionfunction () {}"function"

The null and array results are worth remembering because they often surprise beginners.

JavaScript Is Dynamically Typed

JavaScript is a dynamically typed language.

That means you do not normally declare the type separately.

For example:

let value = 10;

JavaScript sees a number.

Later, this is possible:

value = "Ten";

Now the same variable contains a string.

Check it:

console.log(typeof value);

Output:

string

JavaScript allows this, but changing a variable between unrelated types can make code harder to understand.

Use clear values and predictable types whenever possible.

Real-World Example: Product Data

Consider:

const productName = "Laptop";
const price = 50000;
const quantity = 2;
const inStock = true;

These values use several types:

console.log(typeof productName);
console.log(typeof price);
console.log(typeof quantity);
console.log(typeof inStock);

Output:

string
number
number
boolean

Now calculate:

const total = price * quantity;

console.log(total);

Output:

100000

Understanding types helps you know why calculations and comparisons behave the way they do.

Real-World Example: User Account

A website may store:

const userName = "Riya";
const age = 28;
const verified = false;
let profilePhoto = null;

Here:

  • userName is a string.
  • age is a number.
  • verified is a boolean.
  • profilePhoto currently has no selected value.

These types describe the data more clearly than putting everything into strings.

Why Data Types Matter

Consider:

const price = 500;
const quantity = 2;

console.log(price + quantity);

Output:

502

Now compare:

const price = "500";
const quantity = "2";

console.log(price + quantity);

Output:

5002

Why?

The second example contains strings.

With strings, + joins the values instead of adding them numerically.

This is one of the most common reasons beginners need to understand data types.

String Number vs Real Number

These look similar:

const price1 = 500;
const price2 = "500";

But they are different types.

Check:

console.log(typeof price1);
console.log(typeof price2);

Output:

number
string

This difference becomes important when working with:

  • Form fields
  • API data
  • Calculations
  • Comparisons
  • URL values

You will learn how to convert between types in the JavaScript Type Conversion lesson.

Strict Comparison and Data Types

Consider:

const value1 = 5;
const value2 = "5";

console.log(value1 === value2);

Output:

false

The values may look similar, but one is a number and the other is a string.

Strict equality checks both the value and type.

This is why this course uses === instead of relying on loose comparisons.

You will study this properly in the JavaScript Comparison Operators tutorial.

Common Beginner Mistakes

Putting Numbers Inside Quotes

const price = "500";

This creates a string, not a number.

If you need numerical calculations, use:

const price = 500;

Confusing null and undefined

undefined commonly means no value was assigned.

null is commonly used when your code intentionally represents an empty value.

Assuming Arrays Have typeof "array"

They do not.

const items = [];

console.log(typeof items);

Output:

object

Use:

Array.isArray(items);

Assuming typeof null Returns "null"

It does not.

console.log(typeof null);

Output:

object

Remember this JavaScript behavior rather than designing logic around the result.

Mixing Types Without Checking Them

This can surprise beginners:

console.log("10" + 5);

Output:

105

The first value is a string.

Be clear about the type your program expects.

Best Practices for JavaScript Data Types

Use strings for text:

const customerName = "Riya";

Use numbers for calculations:

const price = 500;

Use booleans for true-or-false states:

const loggedIn = true;

Use null when your program intentionally needs an empty value.

Use arrays for ordered collections.

Use objects for related information.

Check unexpected values with typeof while debugging.

Use Array.isArray() when you specifically need to detect an array.

Avoid changing the same variable between unrelated types unless there is a clear reason.

Beginner Exercise

Create these variables:

const userName = "Amit";
const age = 30;
const loggedIn = true;
let selectedProduct;
const discount = null;

Now print their types:

console.log(typeof userName);
console.log(typeof age);
console.log(typeof loggedIn);
console.log(typeof selectedProduct);
console.log(typeof discount);

Before running the code, predict the output.

Then compare your prediction with the Console.

Pay special attention to:

typeof discount

Why does JavaScript return "object" for null?

Challenge Exercise

Create a product:

const productName = "Monitor";
const price = 12000;
const quantity = 2;
const inStock = true;

Print a sentence:

Monitor costs 12000 and quantity is 2

Then print the type of every variable.

Extra Challenge

Change:

const quantity = "2";

Then try:

console.log(price + quantity);

Predict the output before running it.

Explain why the result changes.

Frequently Asked Questions

What are the data types in JavaScript?

JavaScript primitive types include string, number, boolean, undefined, null, BigInt and Symbol. JavaScript also has objects, which include structures such as normal objects and arrays.

What is a primitive data type?

A primitive is a basic JavaScript value such as a string, number, boolean, undefined, null, BigInt or Symbol.

Is an array a data type in JavaScript?

Arrays are special objects. typeof [] returns "object", while Array.isArray() can identify an array specifically.

What is typeof in JavaScript?

typeof is an operator that returns a string describing the type of a value.

Why does typeof null return object?

This is a long-standing JavaScript behavior. null should still be understood as an intentionally empty value rather than a normal object.

What is the difference between null and undefined?

undefined often means no value has been assigned. null is usually assigned intentionally to represent no value.

Is JavaScript dynamically typed?

Yes. A variable can hold values of different types during execution, although changing types unnecessarily can make code harder to understand.

Are integers and decimals different JavaScript types?

For normal JavaScript numeric values, both use the number type.

What is BigInt used for?

BigInt represents integers beyond the safe integer range of the normal JavaScript number type.

What should I learn after JavaScript data types?

The next lesson is JavaScript operators. You will learn how JavaScript calculates values, assigns values and performs other operations using operators.

Summary

JavaScript data types describe the kinds of values your code works with.

Important primitive types are:

  • String
  • Number
  • Boolean
  • Undefined
  • Null
  • BigInt
  • Symbol

JavaScript also uses objects for more complex data.

You learned that:

typeof "Hello"

returns:

string

while:

typeof 25

returns:

number

You also learned two important JavaScript details:

typeof null

returns:

object

and:

typeof []

also returns:

object

Use Array.isArray() when you specifically need to test for an array.

Understanding data types helps prevent calculation, comparison and form-data mistakes later in your JavaScript code.

Continue Learning JavaScript

Previous Lesson: JavaScript Variables: let, const and var

Course Home: JavaScript Tutorial for Beginners

Next Lesson: JavaScript Operators Explained for Beginners

In the next lesson, you will learn arithmetic, assignment, increment, decrement and other JavaScript operators with practical website examples.

James Parker

James Parker

James Parker is a technology writer and WordPress enthusiast who shares practical guides on SEO, web development, AI tools, and digital growth. He focuses on creating easy-to-follow tutorials that help beginners and professionals build better websites and improve their online presence.