JavaScript Cheat Sheet

Core JavaScript syntax, array methods, and DOM manipulation.

Types & Vars

Concept / Tag Code Snippet Description
Type Check
typeof variable === "string"
Verify data type.
Null Coalescing
const name = user.name ?? "Guest";
Fallback for null/undefined.

Array Tools

Concept / Tag Code Snippet Description
Filter
const young = users.filter(u => u.age < 18);
New array with matches.
Reduce Sum
const sum = orders.reduce((s, o) => s + o.price, 0);
Condense array to total.
Some/Every
arr.some(x => x > 0) | arr.every(...)
Boolean checks.

Object Tricks

Concept / Tag Code Snippet Description
Merge Objects
const combined = { ...obj1, ...obj2 };
Shallow merge clones.
Optional Chain
user?.profile?.bio
Safe nested access.

Promises & Fetch

Concept / Tag Code Snippet Description
Post Request
fetch(url, { method: "POST", body: JSON.stringify(data) });
Send data to API.
Async/Await
const data = await promise;
Handle async synchronous style.

Modern Syntax

Concept / Tag Code Snippet Description
Template String
`Hello ${username}`
Interpolated strings.

Event Handling

Concept / Tag Code Snippet Description
Delegate
parent.addEventListener("click", (e) => { ... });
Single handler for children.

Explore More Cheat Sheets