JavaScript Data Types Cheatsheet
๐งพ JavaScript Data Types Cheatsheet
JavaScript can work with values of different kinds. This cheatsheet gives an overview of primitive types and objects.
โ JavaScript data types โ number โ string โ boolean โ null โ undefined โ symbol โ bigint โ object
#javascript #js #datatypes #primitives #objects #typeof #bigint #symbol #null #undefined
JavaScript data types
JavaScript can work with primitive types (number, string, boolean, null, undefined, symbol, bigint) and objects (arrays, functions, plain objects).
| Type | Category | Description |
|---|---|---|
number | Primitive | Numeric values, including integers and floats. |
string | Primitive | Textual data wrapped in quotes, backticks, or double quotes. |
boolean | Primitive | Logical values: true or false. |
null | Primitive | Intentional absence of any value. |
undefined | Primitive | Variable declared but not assigned a value. |
symbol | Primitive | Unique, immutable identifier. |
bigint | Primitive | Arbitrary-precision integers. |
object | Structural | Collections of key-value pairs, arrays, functions, dates, etc. |
number
Represents both integers and floating-point values.
const age = 30;
const price = 19.99;
const notANumber = NaN;
const infinity = Infinity;
typeof age; // "number"
typeof NaN; // "number"string
Immutable textual data.
const name = "Ada";
const greeting = 'Hello'; // prettier-ignore
const template = `Hi, ${name}`;
typeof name; // "string"boolean
Logical type with only two values.
const isActive = true;
const isAdmin = false;
typeof isActive; // "boolean"null
Represents an absence of value.
const user = null;
typeof user; // "object" (historical quirk)
user === null; // truetypeof null gives "object". This is a long-standing JavaScript quirk.
Instead, use value === null to check for null.
undefined
A variable that has been declared but not assigned a value.
let score;
typeof score; // "undefined"
score === undefined; // truesymbol
Unique and immutable value, often used as object keys.
const id = Symbol("id");
const anotherId = Symbol("id");
id === anotherId; // falsebigint
For integers larger than Number.MAX_SAFE_INTEGER.
const huge = 9007199254740993n;
const alsoHuge = BigInt(9007199254740993);
typeof huge; // "bigint"object
Collections of properties. Includes plain objects, arrays, functions, dates, and more.
const person = { name: "Ada", age: 30 };
const numbers = [1, 2, 3];
const greet = () => "hello";
typeof person; // "object"
typeof numbers; // "object"
typeof greet; // "function"
Array.isArray(numbers); // trueFull-Stack AI Developer Roadmap
From HTML & CSS to working with AI models, all in one structured roadmap.