JavaScript/Data types
[i]Learn· JavaScript language overview

Data types

JavaScript is a multi-paradigm, dynamic language with types and operators, standard built-in objects, and methods. Its syntax is based on the Java and C languages — many structures from those languages apply to JavaScript as well. JavaScript supports object-oriented programming with object prototypes and classes. It also supports functional programming since functions are first-class objects that can be easily created via expressions and passed around like any other object.

This page serves as a quick overview of various JavaScript language features, written for readers with background in other languages, such as C or Java.

Let's start off by looking at the building blocks of any language: the types. JavaScript programs manipulate values, and those values all belong to a type. JavaScript offers seven primitive types:

  • Number: used for all number values (integer and floating point) except for very big integers.
  • BigInt: used for arbitrarily large integers.
  • String: used to store text.
  • Boolean: true and false — usually used for conditional logic.
  • Symbol: used for creating unique identifiers that won't collide.
  • Undefined: indicating that a variable has not been assigned a value.
  • Null: indicating a deliberate non-value.

Everything else is known as an Object. Common object types include:

Functions aren't special data structures in JavaScript — they are just a special type of object that can be called.

Numbers

JavaScript has two built-in numeric types: Number and BigInt.

The Number type is an IEEE 754 64-bit double-precision floating point value, which means integers can be safely represented between -(253 − 1) and 253 − 1 without loss of precision, and floating point numbers can be stored all the way up to 1.79 × 10308. Within numbers, JavaScript does not distinguish between floating point numbers and integers.

console.log(3 / 2); // 1.5, not 1

So an apparent integer is in fact implicitly a float. Because of IEEE 754 encoding, sometimes floating point arithmetic can be imprecise.

console.log(0.1 + 0.2); // 0.30000000000000004

For operations that expect integers, such as bitwise operations, the number will be converted to a 32-bit integer.

Number literals can also have prefixes to indicate the base (binary, octal, decimal, or hexadecimal), or an exponent suffix.

console.log(0b111110111); // 503
console.log(0o767); // 503
console.log(0x1f7); // 503
console.log(5.03e2); // 503

The BigInt type is an arbitrary length integer. Its behavior is similar to C's integer types (e.g., division truncates to zero), except it can grow indefinitely. BigInts are specified with a number literal and an n suffix.

console.log(-3n / 2n); // -1n

The standard arithmetic operators are supported, including addition, subtraction, remainder arithmetic, etc. BigInts and numbers cannot be mixed in arithmetic operations.

The Math object provides standard mathematical functions and constants.

Math.sin(3.5);
const circumference = 2 * Math.PI * r;

There are three ways to convert a string to a number:

  • parseInt(), which parses the string for an integer.
  • parseFloat(), which parses the string for a floating-point number.
  • The Number() function, which parses a string as if it's a number literal and supports many different number representations.

You can also use the unary plus + as a shorthand for Number().

Number values also include NaN (short for "Not a Number") and Infinity. Many "invalid math" operations will return NaN — for example, if attempting to parse a non-numeric string, or using Math.log() on a negative value. Division by zero produces Infinity (positive or negative).

NaN is contagious: if you provide it as an operand to any mathematical operation, the result will also be NaN. NaN is the only value in JavaScript that's not equal to itself (per IEEE 754 specification).

Strings

Strings in JavaScript are sequences of Unicode characters. This should be welcome news to anyone who has had to deal with internationalization. More accurately, they are UTF-16 encoded.

console.log("Hello, world");
console.log("你好,世界!"); // Nearly all Unicode characters can be written literally in string literals

Strings can be written with either single or double quotes — JavaScript does not have the distinction between characters and strings. If you want to represent a single character, you just use a string consisting of that single character.

console.log("Hello"[1] === "e"); // true

To find the length of a string (in code units), access its length property.

Strings have utility methods to manipulate the string and access information about the string. Because all primitives are immutable by design, these methods return new strings.

The + operator is overloaded for strings: when one of the operands is a string, it performs string concatenation instead of number addition. A special template literal syntax allows you to write strings with embedded expressions more succinctly. Unlike Python's f-strings or C#'s interpolated strings, template literals use backticks (not single or double quotes).

const age = 25;
console.log("I am " + age + " years old."); // String concatenation
console.log(`I am ${age} years old.`); // Template literal

Other types

JavaScript distinguishes between null, which indicates a deliberate non-value (and is only accessible through the null keyword), and undefined, which indicates absence of value. There are many ways to obtain undefined:

  • A return statement with no value (return;) implicitly returns undefined.
  • Accessing a nonexistent object property (obj.iDontExist) returns undefined.
  • A variable declaration without initialization (let x;) will implicitly initialize the variable to undefined.

JavaScript has a Boolean type, with possible values true and false — both of which are keywords. Any value can be converted to a boolean according to the following rules:

  1. false, 0, empty strings (""), NaN, null, and undefined all become false.
  2. All other values become true.

You can perform this conversion explicitly using the Boolean() function:

Boolean(""); // false
Boolean(234); // true

However, this is rarely necessary, as JavaScript will silently perform this conversion when it expects a boolean, such as in an if statement (see Control structures). For this reason, we sometimes speak of "truthy" and "falsy", meaning values that become true and false, respectively, when used in boolean contexts.

Boolean operations such as && (logical and), || (logical or), and ! (logical not) are supported; see Operators.

The Symbol type is often used to create unique identifiers. Every symbol created with the Symbol() function is guaranteed to be unique. In addition, there are registered symbols, which are shared constants, and well-known symbols, which are utilized by the language as "protocols" for certain operations. You can read more about them in the symbol reference.

Source: JavaScript language overview by Mozilla Contributors, licensed under CC-BY-SA-2.5. Retrieved 2026-11-18. Changes: Extracted the section "Data types" together with the page introduction; removed the code-block language labels; moved headings up one level; made links absolute; examples are the page's own code blocks, unchanged.