Skip to main content

Developer reference

JavaScript Cheatsheet: Syntax, Collections, DOM, Async

A production-minded JavaScript reference organized around data, transformations, browser interaction, asynchronous boundaries, and failure handling.

JavaScriptbeginner4 min readProgramming reference

Learning overview

Estimated time
4 minutes
Difficulty
Beginner
Prerequisites
No prior experience required
Learning outcome
Explain javascript using a clear mental model · Apply javascript in practical JavaScript work
Last updated
July 18, 2026

Values and bindings

Use const for bindings that are not reassigned and let for intentional reassignment. Use nullish coalescing when zero, false, and empty strings are valid values.

bindings.js
const course = { title: "JavaScript", lessons: 24 };
let completed = 0;
completed += 1;

const displayName = user.name ?? "Anonymous";
const isReady = completed >= course.lessons;

Arrays and objects

Map transforms, filter selects, find returns one matching item, some and every answer predicates, and reduce combines values. Spread creates shallow copies.

collections.js
const lessons = [
  { id: 1, title: "Variables", complete: true },
  { id: 2, title: "Arrays", complete: false },
];

const titles = lessons.map(({ title }) => title);
const remaining = lessons.filter((lesson) => !lesson.complete);
const updated = lessons.map((lesson) =>
  lesson.id === 2 ? { ...lesson, complete: true } : lesson
);

Functions and modules

Prefer explicit inputs and return values. Use named functions for important domain operations and modules to separate public interfaces from implementation details.

progress.js
export function completionPercent(completed, total) {
  if (total <= 0) return 0;
  return Math.round((completed / total) * 100);
}

export default function formatProgress(value) {
  return `${value}% complete`;
}

DOM and events

Query once when possible, listen for semantic events, validate event targets, and render untrusted strings with textContent.

dom.js
const form = document.querySelector("#search-form");
const output = document.querySelector("#result");

form.addEventListener("submit", (event) => {
  event.preventDefault();
  const query = new FormData(form).get("query")?.toString().trim();
  output.textContent = query ? `Searching for ${query}` : "Enter a search term";
});

Promises, async, and errors

Check HTTP status explicitly, preserve useful error context, and model failure in the interface. Use Promise.all for independent work that should fail together.

request.js
async function loadCourse(id, signal) {
  const response = await fetch(`/api/courses/${encodeURIComponent(id)}`, { signal });
  if (!response.ok) {
    throw new Error(`Course request failed: ${response.status}`);
  }
  return response.json();
}

try {
  const course = await loadCourse("javascript", controller.signal);
  renderCourse(course);
} catch (error) {
  if (error.name !== "AbortError") renderError(error);
}

Debugging checklist

Reproduce the failure with the smallest input, inspect types and state transitions, pause at the first wrong value, and distinguish network, parsing, domain, and rendering failures.

  • Read the first relevant stack frame
  • Check value and type together
  • Use breakpoints instead of adding many logs
  • Inspect network status and response payload
  • Test rejected promises and empty data
  • Write a regression test before closing the bug

Frequently asked questions

Does this JavaScript cheatsheet include every API?

No. It focuses on transferable language and browser patterns. Use standards-based documentation for complete API signatures and compatibility.

Should I use map or forEach?

Use map when you need a new array of transformed values. Use forEach for deliberate side effects when no returned collection is needed.

Topic graph

A taxonomy-generated path through this subject.

  1. JavaScript
  2. Programming reference
  3. javascript
  4. reference
  5. dom
  6. async
  7. What Is JavaScript in Programming?
  8. Learn JavaScript: From Fundamentals to Web Applications
  9. JavaScript Tutorial: Build a Filterable Task List

Recommended automatically from shared technologies, topics, intent, and difficulty.

Hand-picked companion pages that deepen this topic.

Your next steps

Continue learning

  1. 1glossaryWhat Is JavaScript in Programming?
  2. 2guidesLearn JavaScript: From Fundamentals to Web Applications
  3. 3guidesJavaScript Tutorial: Build a Filterable Task List
  4. 4cheatsheetsPython Cheatsheet: Syntax, Collections, Files, and OOP