Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

JavaScript has seven primitive data types—Boolean, null, undefined, Number, BigInt, String, and Symbol—and one other language type, Object. A variable can hold different types of values at different times, and JavaScript sometimes converts values automatically. Knowing the type inventory, how to check a value, and when Number is not precise enough will help you avoid common bugs.

What are the data types in JavaScript?

A data type describes what kind of value an expression produces and what operations make sense for it. JavaScript’s seven primitive types are Boolean, null, undefined, Number, BigInt, String, and Symbol. Object is the other language type. Arrays and functions are object forms; functions can also be called.

Type What it represents Example
Boolean A truth value true, false
null An explicitly absent value null
undefined A value that has not been provided or assigned undefined
Number Ordinary integers and floating-point numbers 42, 3.14
BigInt An integer beyond Number’s safe-integer range, or an integer represented with BigInt 9007199254740993n
String Text "hello"
Symbol A unique symbol value, often used as an object property key Symbol("id")
Object A collection of properties; arrays and functions are object forms { name: "Ada" }

Primitive values are immutable: an operation does not change the value itself. Objects are mutable; their properties can be added, removed, or changed. Primitive values can still provide useful methods, such as string methods, through JavaScript’s automatic wrapper behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do JavaScript variables relate to types?

JavaScript is dynamically typed: a variable is not permanently assigned one type. It holds a value, and that value can be replaced with one of a different type:

let value = 42;
value = "hello";

The number did not transform into text; the variable now refers to a different value. The let declaration permits reassignment. A const binding cannot be reassigned, though an object held by a const can still have its properties changed.

Some operations also perform implicit conversion, or coercion. For example, adding a number and a string produces a string:

const result = 5 + "2"; // "52"

MDN Web Docs notes that implicit conversions are convenient but can create subtle bugs when a conversion occurs unexpectedly or in the opposite direction from what the programmer intended. When the intended type is not obvious, make the conversion explicit and inspect the resulting value.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What is the difference between null and undefined?

Both types have a single value, but they commonly communicate different things. undefined often means a value has not been supplied: a declared variable without an initial value is undefined, as is a missing object property or the result of a function that returns without a value. null is an explicit null value, often used to indicate the absence of an object.

let selectedItem;
const profile = { name: "Ada" };

console.log(selectedItem); // undefined
console.log(profile.age);  // undefined
console.log(null);         // explicitly absent

These are common conventions, not a universal contract: APIs and codebases may use null or undefined differently. Follow the documented convention of the API you are using.

Why does typeof null return object?

typeof is useful for many values, but null is a longstanding exception: typeof null returns "object" for historical reasons. It does not mean that null is an object. Check for null directly:

if (value === null) {
  // value is null
}

How does typeof work?

typeof returns a string describing a value’s type. Common results include:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Value typeof result
undefined "undefined"
true "boolean"
42 "number"
42n "bigint"
"hello" "string"
Symbol("id") "symbol"
() => {} "function"
{} "object"
null "object" (historical exception)

Functions are objects with callable behavior, which is why typeof reports "function" for them. For other object values, including arrays, it reports "object". Since null has that same result, use the direct null check when distinguishing it.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When should you use BigInt instead of Number?

Number represents integers and decimals using IEEE 754 double-precision binary floating point. It is the usual choice for everyday arithmetic, but not every integer can be represented distinctly. Its safe-integer range is from −(253 − 1) through 253 − 1. Outside that range, distinct integers may resolve to the same Number value.

Use BigInt when you need integer values beyond that safe-integer boundary. You can write a BigInt literal with an n suffix or create one with BigInt():

const largeInteger = 9007199254740993n;
const alsoBigInt = BigInt("9007199254740993");

BigInt is a separate type, not a more precise form of Number that can be freely substituted into Number arithmetic. Keep values in the appropriate type, and convert deliberately when working with APIs or operations that expect Number.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How can you avoid type-related bugs?

  • When debugging, inspect both the value and its type with tools such as console.log(value, typeof value); check null separately.
  • Convert text input explicitly before numeric calculations, and validate that the conversion produced a usable number.
  • Prefer strict equality (===) so comparisons do not silently coerce values. Use coercive equality only when you intentionally want its conversion rules.
  • Use Number for ordinary numeric work and BigInt for integers that must remain exact beyond Number’s safe range; do not mix them in arithmetic without an intentional conversion.

For a deeper reference, see MDN Web Docs’ JavaScript data structures guide.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.