Cheatsheet
Modern JavaScript Cheatsheet
Every core JavaScript feature from ES6 onward. If you learned JS before 2018, this is your update path.
JavaScript changes fast. ES6 (2015) introduced let/const, arrow functions, classes, and template literals. Every year since has added meaningful syntax. If your mental model of JavaScript is stuck at ES5, this cheatsheet is the update.
Use it as a reference, then drop the sections you keep forgetting into Ellie for a review deck.
Variables and scope
`let` and `const` are block-scoped (unlike `var`). Prefer `const` by default; use `let` only when reassignment is needed. Avoid `var` entirely in new code.
Destructuring
Object: `const { name, age } = user`. Rename: `const { name: firstName } = user`. Default: `const { name = 'Anonymous' } = user`.
Array: `const [first, second, ...rest] = list`.
Function parameters: `function greet({ name, age = 18 })`.
Optional chaining and nullish coalescing
`user?.profile?.name` — returns undefined if any link is nullish.
`value ?? 'default'` — returns default only if value is null or undefined (unlike `||` which also treats 0 and '' as falsy).
`user?.name ?? 'Guest'` — chain them for safe defaults.
Async patterns
`async function f() { const data = await fetch(url); return data.json(); }`.
Top-level await (ES2022): `const data = await fetch(url)` at module level, no wrapper needed.
`Promise.all([p1, p2])` for parallel; `Promise.allSettled` when partial failures are OK.
Classes
Fields: `class Foo { count = 0; }`. Private: `#count`. Static: `static instances = 0`.
Getters/setters: `get name() { return this.#name; }`.
Modules
`export const foo = 1; export default class Bar {}`. Named import: `import { foo } from './x.js'`. Default: `import Bar from './x.js'`.
Frequently asked questions
Should I still use var?
No. `let` and `const` cover every case with better scoping.
Arrow function or regular function?
Arrow for callbacks and short functions. Regular when you need `this` binding, `arguments`, or generator/async functions with clearer semantics.
Is optional chaining safe for method calls?
Yes. `user?.getName?.()` returns undefined if either the object or the method is missing.
When to use `??` vs `||`?
`??` for genuine null/undefined defaults. `||` if you want to treat all falsy values (0, '', false) as absent.
What is top-level await?
In modules only, you can `await` at the top level without wrapping in an async function. Not supported in CommonJS.
Keep exploring
Made for exam season
Pass that exam.
Turn your notes into flashcards and quizzes in seconds. Study smarter — start free today.
