Skip to content
Guest
← All References
JavaScript Baseline Widely Available

Modern JavaScript Reference

Essential modern JavaScript syntax, data structures, DOM APIs, and async patterns in one scannable cheat sheet.

const/let, ?., ??, Set/Map, querySelector, async/await, import/export

Modern Syntax & Operators

SyntaxPurposeExample
const / letBlock-scoped bindingsconst max = 10; let count = 0;
=== / !==Strict equality (no coercion)if (role === 'admin')
??Nullish coalescing defaultconst name = input ?? 'Guest';
?.Optional chaininguser?.profile?.avatar
{ a, b } = objDestructuringconst { title, level = 'Beginner' } = course;
...Spread / Restconst copy = { ...obj, done: true };

Collections & Iteration

APIPurposeExample
for (const x of arr)Clean loop supporting break / continuefor (const [i, v] of arr.entries())
.map() / .filter() / .reduce()Immutable array transformsnums.filter(n => n > 0)
new Set(arr)Unique values with O(1) .has()[...new Set(tags)]
new Map()Key-value lookup with .get()/.set()counts.set('html', 16)
structuredClone(obj)Deep clone nested objects/arraysconst deep = structuredClone(state);

DOM, Events & Browser APIs

APIPurposeExample
document.querySelector()Find first matching elementdocument.querySelector('#btn')
el.textContentSet/read plain text safely (XSS-safe)el.textContent = 'Saved';
el.classList.toggle()Add/remove CSS classespanel.classList.toggle('open', isOpen)
el.closest(selector)Event delegation helpere.target.closest('button[data-id]')
parent.replaceChildren()Replace child nodes cleanlylist.replaceChildren(...items)
localStorage + JSONPersist client-side statelocalStorage.setItem(k, JSON.stringify(v))
setTimeout / clearTimeoutDelayed execution & debouncingclearTimeout(id); id = setTimeout(fn, 300)

Async, Errors & Modules

PatternPurposeExample
async / awaitLinear asynchronous control flowconst res = await fetch(url);
try / catch / finallyResilient error handling & cleanupfinally { btn.disabled = false; }
export / importNative ES Modulesimport { clamp } from './math.js';
class { #private }Encapsulated private class fields#completed = new Set();

Search courses, lessons, and references

Type to search across all courses, lessons, and quick references.

Press Esc to close Powered by Pagefind