Free tools Windows power users keep installed
One-click scans. No signup required.
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:
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →- 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.
#1 Best Overall
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:
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Rank #2
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.
Recommended Free Tools
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.emailwhen no email was set; - a function ends without a
returnstatement, 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.
Rank #4
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:
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.
Best Value
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.
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:
| 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:
Quick Recap
- Log both values in one line:
console.log(value, typeof value); - If the type is
'object'and you expected an array, callArray.isArray(value). - If the value might be null, test it with
value === nullbefore reading its properties. - For text from a form or file, convert it explicitly with
Number(text)and check the result withNumber.isNaN(). Be aware thatNumber('')returns0, notNaN, so check for empty strings first.
Common beginner mistakes
- Assuming
typeof nulltells 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' + 2produces'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.




