A JavaScript cheat sheet is a compact map of the language you run in the browser and in Node.js. This page focuses on modern syntax (let/const, arrows, modules), the array methods you use every day, and async code with fetch and async/await.
This JavaScript cheat sheet is written for people searching for a fast, accurate reference: students, junior developers, and teams shipping production software. Pin it, copy the snippets, and come back when syntax slips.
Quick reference
- Declare:
constby default,letwhen reassigned, nevervarin new code. - Types: string, number, bigint, boolean, null, undefined, symbol, object.
- Equality:
===and!==. UseObject.isfor edge NaN checks. - Arrows:
() => valueinheritsthis. Usefunctionwhen you need a constructable method. - Template: `
Hello ${name}` for strings. Never build HTML from raw user input. - Destructure:
const {title, slug} = post;andconst [first, ...rest] = list. - Spread:
{...a, ...b}and[...items, next]. - Optional:
user?.address?.cityandvalue ?? fallback(nullish, not falsy). - JSON:
JSON.parse/JSON.stringify. Wrap parse in try/catch. - Modules:
export function x(){}andimport {x} from "./x.js"withtype="module".
Copy-paste examples
Filter, map, and reduce
Prefer these over hand-rolled for-loops when transforming lists.
const orders = [
{ id: 1, total: 20, paid: true },
{ id: 2, total: 45, paid: false },
{ id: 3, total: 15, paid: true },
];
const paidTotal = orders
.filter((o) => o.paid)
.map((o) => o.total)
.reduce((sum, n) => sum + n, 0);
console.log(paidTotal); // 35Fetch JSON with async/await
Always check res.ok before calling .json().
async function loadProjects() {
const res = await fetch('/api/projects.php?public=1');
if (!res.ok) throw new Error('HTTP ' + res.status);
const data = await res.json();
return data.projects ?? [];
}Common mistakes
- Using
==and accidentally coercing"",0, andfalseinto equality bugs. - Mutating arrays with
sort()in place when you needed[...list].sort(). - Forgetting
awaitand logging a Promise object instead of data. - Attaching listeners in a loop without
{ once: true }or abort controllers — duplicate handlers. - Storing objects in
localStoragewithoutJSON.stringify/JSON.parse.
FAQ
- Is JavaScript the same as Java? No. Different languages, different runtimes, similar names by accident. JavaScript runs in browsers and Node. Java runs on the JVM.
- Should I learn vanilla JS before React? Yes. React is JavaScript. If you cannot debug an event listener or a fetch call, components will feel like magic.
- What is the event loop in one sentence? JavaScript runs one call stack; async callbacks and promises queue as macrotasks/microtasks and run when the stack is empty.
- Do I need TypeScript? For apps that last, yes. For a first cheat-sheet week, master JS types and
===first, then add TypeScript.
Related JavaScript cheat sheets
Build with this stack
When a cheat sheet is not enough — you need a production app, a student FYP, or a custom dashboard — ArpaNeuro builds custom web development and also sells ready-made source code. Request a quote and tell us the stack.
Browse software development services or the source code marketplace if you want a working codebase instead of starting from a blank file.