JavaScript Data Types: A Complete Beginner Guide

JavaScript has 8 data types split into primitives and objects. Learn each type, how to check them with typeof, and which one to use for different kinds of data.

7 min read

Every value in JavaScript belongs to one of 8 data types. These types determine what you can do with a value, how it behaves in expressions, and how it is stored in memory.

The 8 types split into two categories. Seven are primitives: simple, immutable values that represent a single piece of data. One is object: a mutable collection that can hold multiple values and even other objects.

Here is the full list at a glance:

TypeCategoryExampleWhat it stores
stringPrimitive"hello"Text
numberPrimitive42, 3.14Integers and floats
bigintPrimitive9007199254740991nVery large integers
booleanPrimitivetrue, falseLogical yes/no
undefinedPrimitiveundefinedNot assigned yet
nullPrimitivenullIntentionally empty
symbolPrimitiveSymbol("id")Unique identifiers
objectNon-primitive{ name: "Alex" }Collections of data

string: Text Values

A string stores a sequence of characters. You create strings with single quotes, double quotes, or backticks. The choice is mostly a style preference, though backticks enable template literals with embedded expressions.

javascriptjavascript
let single = 'Hello';
let double = "World";
let template = `The result is ${10 + 5}`;
 
console.log(single, double, template);

The console prints "Hello", "World", and "The result is 15". The backtick version evaluates the expression inside the curly braces and inserts the result into the string.

Strings are immutable. Methods like toUpperCase do not change the original string; they return a new one. You can check if a value is a string with the typeof operator, which returns the string "string".

number: Integers and Floats

JavaScript has a single number type that covers both integers and floating-point values. There is no separate int or float type like in other languages. All numbers are 64-bit floating-point values following the IEEE 754 standard.

javascriptjavascript
let integer = 42;
let float = 3.14;
let negative = -10;
let scientific = 1.5e6; // 1,500,000
 
console.log(typeof integer, typeof float);

Both typeof calls return "number". The number type also includes special values like Infinity, -Infinity, and NaN (Not a Number), which represents the result of an invalid math operation.

Numbers are precise up to about 15 digits. For integers larger than 2^53 - 1, precision starts to degrade. That is where bigint comes in.

bigint: Very Large Integers

bigint was introduced in ES2020 for integers too large for the number type. You create a bigint by appending n to an integer literal or by calling the BigInt function.

javascriptjavascript
let safe = 9007199254740991;     // max safe integer for number
let big = 9007199254740991n;     // bigint
let huge = BigInt("9007199254740991999");
 
console.log(typeof big);

The typeof check returns "bigint". You can perform arithmetic with bigints, but you cannot mix them with regular numbers in the same operation without explicit conversion. Bigints are useful for cryptography, high-precision timestamps, and large database IDs.

boolean: True or False

A boolean has exactly two possible values: true or false. Booleans are the result of comparisons and logical operations. They control the flow of your program through if statements and loops.

javascriptjavascript
let isLoggedIn = true;
let isExpired = false;
 
console.log(10 > 5);     // true
console.log("a" === "b"); // false

Every value in JavaScript can be converted to a boolean context. Values that convert to false are called falsy: false, 0, "" (empty string), null, undefined, and NaN. Everything else is truthy.

This is the foundation of conditional logic in JavaScript.

undefined: No Value Assigned

undefined is the default value of a variable that has been declared but not assigned. It is also the return value of functions that do not explicitly return anything.

javascriptjavascript
let unassigned;
console.log(unassigned);        // undefined
console.log(typeof unassigned); // "undefined"
 
function noReturn() {}
console.log(noReturn());        // undefined

undefined means the absence of a value was not intentional. The JavaScript engine put it there because nothing else was assigned. You should rarely assign undefined to a variable yourself; use null for intentional emptiness instead.

null: Intentionally Empty

null is an explicit assignment that means this value is empty on purpose. It represents the intentional absence of any object value.

javascriptjavascript
let selectedUser = null; // no user selected yet
console.log(selectedUser);        // null
console.log(typeof selectedUser); // "object" (historical bug)

The typeof null returning "object" is a well-known bug in JavaScript that dates back to its first version. It has never been fixed because too much existing code depends on it. To check for null reliably, use a strict equality comparison: value === null.

For a deeper comparison of undefined and null, see the undefined vs null guide.

symbol: Unique Identifiers

A symbol is a guaranteed unique value, even if two symbols are created with the same description. Symbols were introduced in ES6 and are mainly used as unique property keys on objects.

javascriptjavascript
let id1 = Symbol("id");
let id2 = Symbol("id");
 
console.log(id1 === id2); // false

Even though both symbols have the same description "id", they are completely different values. Symbols are useful when you need to add a property to an object without risking a name collision with other code. They are an advanced feature that most beginners do not need immediately.

object: Collections of Data

An object is a mutable collection of key-value pairs. Almost everything that is not a primitive is an object. This includes plain objects, arrays, functions, dates, regular expressions, maps, and sets.

javascriptjavascript
let user = { name: "Alex", age: 30 };
let colors = ["red", "green", "blue"];
let greet = function() { return "Hello"; };
 
console.log(typeof user);   // "object"
console.log(typeof colors); // "object"
console.log(typeof greet);  // "function" (functions are callable objects)

Objects are stored and copied by reference, not by value. When you assign an object to a new variable, both variables point to the same object in memory. Changing one affects the other.

This is the key behavioral difference between primitives and objects.

For a complete exploration of how primitives and objects behave differently in memory, see the primitive vs reference types guide.

Rune AI

Rune AI

Key Insights

  • JavaScript has 8 data types: 7 primitives and 1 object type.
  • Primitives include string, number, bigint, boolean, undefined, null, and symbol.
  • Objects include arrays, functions, dates, and plain objects.
  • Use typeof to check the type of any value.
  • undefined is automatic; null is intentional.
RunePowered by Rune AI

Frequently Asked Questions

How many data types does JavaScript have?

JavaScript has 8 data types: string, number, bigint, boolean, undefined, null, symbol, and object. The first 7 are primitives. Object is the only non-primitive type and includes arrays, functions, dates, and plain objects.

What does typeof return for an array?

typeof returns 'object' for arrays because arrays are a type of object in JavaScript. To check specifically for an array, use Array.isArray() instead of typeof.

What is the difference between undefined and null?

undefined means a variable has been declared but has not been assigned a value. null is an intentional assignment that means no value or empty. undefined is the default; null is explicit.

Conclusion

JavaScript has 8 data types organized into primitives and objects. Primitives are immutable single values like strings, numbers, and booleans. Objects are mutable collections like arrays and plain objects. Understanding the type system helps you choose the right data structure and avoid type-related bugs.