JavaScript Cheat Sheet
A searchable, printable reference of modern JavaScript — syntax, arrays, strings, objects, async/await, DOM and ES2022+ features. Free.
Variables & types
10let x = 1;
const PI = 3.14;
typeof value
Number('42')
String(42)
parseInt('42px', 10)
Boolean(0)
value ?? 'default'
a?.b?.c
Array.isArray(x)
Functions
9function add(a, b) { return a + b; }
const add = (a, b) => a + b;
const f = (a = 1) => a;
function f(...args) {}
f(...arr)
const { a, b } = obj;
const [x, y] = arr;
(function(){})()
fn.bind(this)
Strings
10`Hello ${name}`
str.length
str.includes('a')
str.slice(0, 3)
str.replace(/a/g, 'b')
str.split(',')
str.trim()
str.toUpperCase()
str.padStart(3, '0')
str.at(-1)
Arrays
11arr.map(x => x * 2)
arr.filter(x => x > 0)
arr.reduce((a, b) => a + b, 0)
arr.find(x => x.id === 1)
arr.some(x => x > 0)
arr.every(x => x > 0)
arr.includes(3)
arr.sort((a, b) => a - b)
[...new Set(arr)]
arr.flat(Infinity)
arr.at(-1)
Objects
9Object.keys(obj)
Object.values(obj)
Object.entries(obj)
{ ...a, ...b }
Object.assign({}, a, b)
Object.freeze(obj)
{ [key]: value }
obj.hasOwnProperty('x')
structuredClone(obj)
Async & promises
9async function f() {}
await fetch(url)
Promise.all([p1, p2])
Promise.allSettled([p1, p2])
Promise.race([p1, p2])
new Promise((res, rej) => {})
try { await f(); } catch (e) {}
setTimeout(fn, 1000)
queueMicrotask(fn)
Control flow
9if (a) {} else if (b) {} else {}
a ? b : c
switch (x) { case 1: break; }
for (const x of arr) {}
for (const k in obj) {}
while (cond) {}
arr.forEach((x, i) => {})
break / continue
label: for (...) { break label; }
DOM & events
10document.querySelector('.x')
document.querySelectorAll('.x')
el.addEventListener('click', fn)
el.classList.toggle('active')
el.dataset.id
el.textContent = 'hi'
el.setAttribute('aria-hidden', true)
e.preventDefault()
el.closest('.parent')
document.createElement('div')
Classes & modules
9class A extends B {}
constructor() { super(); }
#private = 1;
static create() {}
get value() {}
export default fn;
export { a, b };
import x, { y } from './m.js'
const m = await import('./m.js')
No entry matches “:q”.
About JavaScript Cheat Sheet
This JavaScript cheat sheet is a searchable, single-page reference to the modern language: variables and types, functions, strings, arrays, objects, async and promises, control flow, DOM and events, and classes and modules. Each entry pairs a real code snippet with a one-line explanation of what it does.
It is written for the JavaScript people actually ship today — let and const, arrow functions, destructuring, spread, optional chaining, template literals, async/await and ES modules — so it doubles as a quick refresher when you switch back from another language.
The whole sheet loads client-side and is free. Filter it live with the search box, jump between sections from the sticky table of contents, click any snippet to copy it, and print the page for a desk-side JavaScript reference.
How to use JavaScript Cheat Sheet
- Open the sheet and skim the section list — from Variables & types through DOM & events to Classes & modules.
- Type into the search box to filter every row live; the match counter shows how many snippets fit.
- Use the sticky table of contents to jump straight to a section such as Async & promises.
- Click a snippet, or its copy icon, to copy the code to your clipboard.
- Click Print for a clean, paper-friendly copy of the whole reference.