JavaScript Cheat Sheet

The JavaScript syntax, built-in methods and browser calls you reach for daily, in one reference.

JavaScript reference
Runs locally in your browser

About the JavaScript Cheat Sheet

This reference gathers the JavaScript you use most into fourteen tables: declarations and scope, type checks, operators, the string and array method sets in full, numbers and Math, objects, destructuring, functions, loops, classes, promises, the built-in collections and the DOM calls that matter. Every row states what an expression returns rather than repeating the name back at you, so scanning is faster than searching documentation.

The array table flags which methods rewrite the array in place and which hand back a copy, a distinction that grew sharper once toSorted, toReversed, toSpliced and with shipped everywhere. Notes call out the behaviour that bites: typeof null answering object, 0.1 + 0.2 landing on 0.30000000000000004, fetch resolving happily on a 404 response, and JSON.stringify quietly dropping undefined values from objects while turning them into null inside arrays.

Nothing here is framework specific, so the sheet stays accurate whether you write plain scripts, Node services or React components. Filter by a word such as promise, clone or class to jump to the handful of rows you actually need, then copy the result as Markdown. To reformat the code you are writing against it, open the JavaScript Beautifier, or look for syntax errors with the JavaScript Validator.

How to use

  1. Choose a section such as Arrays or Promises and async to focus the reference.
  2. Or type a method name in the filter box to see only the rows that mention it.
  3. Use Copy for Markdown tables you can paste into a README, or Download the .md file.

Common questions

What is the difference between let, const and var?
let and const are block scoped and stay unreachable until their declaration runs. var is function scoped and hoisted as undefined, which is what makes it surprising inside loops.
Which array methods change the original array?
push, pop, shift, unshift, splice, sort, reverse and fill all mutate. slice, map, filter, concat, toSorted, toReversed, toSpliced and with return a new array instead.
When should I use ?? instead of ||?
Use ?? when 0, an empty string or false are values you want to keep, because || replaces every falsy value while ?? only replaces null and undefined.
How do I deep clone an object in JavaScript?
structuredClone copies nested objects along with Map, Set, Date and typed arrays. A JSON.parse of JSON.stringify loses those types and throws on circular references.
Does await block the whole page?
No. It suspends only the async function it sits inside and returns control to the event loop, so rendering and other handlers keep running.