โค Like
๐Ÿ”– Save
๐Ÿ”— Share
@thedevspaceio
@thedevspaceio

JavaScript Data Types Cheatsheet

@thedevspaceio

๐Ÿงพ 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).

TypeCategoryDescription
numberPrimitiveNumeric values, including integers and floats.
stringPrimitiveTextual data wrapped in quotes, backticks, or double quotes.
booleanPrimitiveLogical values: true or false.
nullPrimitiveIntentional absence of any value.
undefinedPrimitiveVariable declared but not assigned a value.
symbolPrimitiveUnique, immutable identifier.
bigintPrimitiveArbitrary-precision integers.
objectStructuralCollections of key-value pairs, arrays, functions, dates, etc.

number

Represents both integers and floating-point values.

js
const age = 30;
const price = 19.99;
const notANumber = NaN;
const infinity = Infinity;
 
typeof age; // "number"
typeof NaN; // "number"

string

Immutable textual data.

js
const name = "Ada";
const greeting = 'Hello'; // prettier-ignore
const template = `Hi, ${name}`;
 
typeof name; // "string"

boolean

Logical type with only two values.

js
const isActive = true;
const isAdmin = false;
 
typeof isActive; // "boolean"

null

Represents an absence of value.

js
const user = null;
 
typeof user; // "object" (historical quirk)
user === null; // true

typeof 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.

js
let score;
 
typeof score; // "undefined"
score === undefined; // true

symbol

Unique and immutable value, often used as object keys.

js
const id = Symbol("id");
const anotherId = Symbol("id");
 
id === anotherId; // false

bigint

For integers larger than Number.MAX_SAFE_INTEGER.

js
const huge = 9007199254740993n;
const alsoHuge = BigInt(9007199254740993);
 
typeof huge; // "bigint"

object

Collections of properties. Includes plain objects, arrays, functions, dates, and more.

js
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); // true

Full-Stack AI Developer Roadmap

From HTML & CSS to working with AI models, all in one structured roadmap.

@thedevspaceio
www.thedevspace.io