DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk5 min

Understanding JavaScript Data Types: A Beginner’s Guide

JavaScript has seven primitive types plus Object. Learn how each behaves, why typeof null returns 'object', how coercion surprises beginners, and when BigInt beats Number.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

JavaScript has seven primitive types: Boolean, null, undefined, Number, BigInt, String, and Symbol. Object is the eighth language type, and it covers arrays, functions, dates, and most other structured values. Learning these eight types, the one well-known quirk in typeof, and the point where Number stops being exact will prevent most type-related bugs a beginner runs into.

The eight types at a glance

The table below lists each type with a typical value and the result of the typeof operator. The entries follow the classification in MDN Web Docs’ JavaScript reference.

As an Amazon Associate I earn from qualifying purchases.

Type Example values Result of typeof
Boolean true, false 'boolean'
null null 'object' (a long-standing quirk, covered below)
undefined undefined 'undefined'
Number 42, 3.14, NaN 'number'
BigInt 9007199254740993n 'bigint'
String 'hello' 'string'
Symbol Symbol('id') 'symbol'
Object {}, [], new Date() 'object'
Function (a kind of object) function () {} 'function'

Primitives and objects are different kinds of value

The first seven types are primitives. A primitive is a value by itself: the number 42 is the same 42 wherever it appears. Objects are collections of properties, and you can change them in place by adding, removing, or replacing properties. Two consequences matter early on:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Changing a property of an object is visible to every variable that refers to that same object.
  • Primitive values can still use methods, such as 'hello'.toUpperCase(). JavaScript wraps the primitive temporarily so the method is available, so a primitive is not a value with no behavior.

Arrays and functions are objects too. That is why typeof [] returns 'object'. To check for an array, use Array.isArray() instead.

Variables hold values, and values carry types

A variable in JavaScript has no fixed type. The same variable can hold a number at one moment and a string later:

let value = 42;
value = 'hello';   // valid: the variable now holds a string

The type belongs to the value, not to the variable’s name. Reassignment replaces the value and its type together.

Implicit coercion

Some operators convert values to a different type without being asked. The results are sometimes surprising:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
console.log('5' - 2);   // 3   (the string is converted to a number)
console.log('5' + 2);   // '52' (the number is converted to a string)
console.log('5' * '2'); // 10

The same operator produces different results depending on the types of its operands, so a mistake in one part of the program can look like correct output elsewhere. MDN’s data structures guide puts it this way:

“Implicit coercions are very convenient, but can create subtle bugs when conversions happen where they are not expected, or where they are expected to happen in the other direction (for example, string to number instead of number to string).”

The practical defense is to convert input explicitly with Number(), String(), or Boolean(), and to use strict equality (===) for comparisons. Loose equality (==) runs its own conversion rules; 0 == '' is true, while 0 === '' is false.

undefined and null

Both represent “no value,” but they are used for different purposes.

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

undefined

undefined is what JavaScript itself produces when something has not been given a value. You will see it when:

  • a variable is declared with let total; and never assigned;
  • an object property does not exist, such as user.email when no email was set;
  • a function ends without a return statement, or returns nothing.

typeof also returns 'undefined' for an undeclared name such as typeof missingName, which does not throw an error. Reading the undeclared name directly, however, does throw a ReferenceError.

null

null is a value that a program assigns on purpose to mean “nothing here.” Many APIs use it to show that an object is expected but absent. Code and documentation do not always agree on this convention, so when you work with a library, check how that library’s documentation uses null and undefined.

The typeof null quirk

typeof null returns 'object'. This is a historical behavior that MDN documents, and it cannot be changed without breaking existing code. It does not mean null is an object. To test for null, compare directly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
function describe(value) {
  if (value === null) return 'no value (null)';
  return typeof value;
}
console.log(describe(null));  // 'no value (null)'
console.log(describe({}));    // 'object'

Number: exact integers only up to a limit

Number holds integers and decimal values using the IEEE 754 double-precision binary format. That single format covers ordinary whole numbers, fractions, Infinity, and NaN. Every Number is stored as a 64-bit binary value, which has two effects beginners should know about.

First, integers are exact only within the safe-integer range, from -(2^53 − 1) to 2^53 − 1. The largest safe integer is available as Number.MAX_SAFE_INTEGER, which equals 9007199254740991. Beyond that range, two different integers can be stored as the same Number:

console.log(Number.MAX_SAFE_INTEGER);            // 9007199254740991
console.log(9007199254740992 === 9007199254740993); // true: the second literal rounds down

Second, decimal fractions are approximations in binary. 0.1 + 0.2 produces 0.30000000000000004. This is a property of the format, not a JavaScript bug, and it affects money and measurement calculations in the same way in most languages that use IEEE 754.

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

BigInt: integers beyond the safe range

BigInt stores integers of arbitrary size. You create one by adding an n suffix to an integer literal or by calling BigInt(). BigInt is a separate type from Number, and the two do not mix in arithmetic:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Aspect Number BigInt
Values it represents Integers and decimal fractions Integers only
Exact integer range -(2^53 − 1) to 2^53 − 1 Arbitrary size
Literal syntax 42 42n
Result of typeof 'number' 'bigint'
Mixing with the other type Not allowed in arithmetic with BigInt; it throws a TypeError Not allowed in arithmetic with Number; it throws a TypeError
const big = 9007199254740993n;
console.log(big + 1n);        // 9007199254740994n
console.log(big + 1);         // TypeError: Cannot mix BigInt and other types
console.log(Number(10n) + 5); // 15, after an explicit conversion

Use Number for everyday counts, indexes, and amounts within the safe range. Reach for BigInt when integer results must stay exact beyond 2^53, such as large identifiers or integer arithmetic at that scale. Note that BigInt cannot represent fractions, so it is not a replacement for Number in decimal calculations.

Checking types while debugging

When a value behaves unexpectedly, the fastest check is to print the value and its type together:

  1. Log both values in one line: console.log(value, typeof value);
  2. If the type is 'object' and you expected an array, call Array.isArray(value).
  3. If the value might be null, test it with value === null before reading its properties.
  4. For text from a form or file, convert it explicitly with Number(text) and check the result with Number.isNaN(). Be aware that Number('') returns 0, not NaN, so check for empty strings first.

Common beginner mistakes

  • Assuming typeof null tells you whether a value is null. Use === null.
  • Using == and expecting strict behavior. Prefer === unless you intend the conversion.
  • Doing arithmetic with user input without converting it first, so '5' + 2 produces '52'.
  • Expecting integer arithmetic to stay exact above Number.MAX_SAFE_INTEGER.
  • Mixing BigInt and Number in one expression.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.