JavaScript cheat sheet

JavaScript cheat sheet and syntax reference

A practical JavaScript cheat sheet for syntax, variables, data types, operators, loops, functions, arrays, objects, classes, modules, promises, async/await, DOM, fetch, and regex.

JavaScript quick reference by topic

  1. Variables and constants

    Use let for values that change and const for bindings that should not be reassigned.

    const name = "Ada";
    let count = 0;
    count += 1;
    • JavaScript variables
    • let const
    • declare variable
    Study Variables
  2. Data types

    JavaScript values include strings, numbers, booleans, null, undefined, bigint, symbols, and objects.

    typeof "hello";
    typeof 42;
    value === null;
    • JavaScript data types
    • typeof
    • primitive values
    Study Data types
  3. Operators and comparisons

    Combine arithmetic, assignment, logical operators, and strict equality to write predictable expressions.

    total += price;
    value === expected;
    isReady && run();
    • JavaScript operators
    • strict equality
    • logical operators
    Study Basic operators, maths
  4. Conditions and loops

    Control program flow with if, switch, while, for, break, and continue.

    if (score >= 90) { grade = "A"; }
    for (const item of items) { render(item); }
    • JavaScript if else
    • JavaScript loops
    • switch statement
    Study Loops: while and for
  5. Functions

    Package reusable behavior with declarations, expressions, parameters, return values, and arrow functions.

    function add(a, b) { return a + b; }
    const double = (n) => n * 2;
    • JavaScript functions
    • arrow function
    • return value
    Study Functions
  6. Arrays

    Store ordered values and transform lists with map, filter, reduce, find, some, and every.

    items.map((item) => item.name);
    items.filter(Boolean);
    items.reduce((sum, n) => sum + n, 0);
    • JavaScript arrays
    • array methods
    • map filter reduce
    Study Array methods
  7. Objects

    Group related data with object literals, properties, methods, destructuring, spread, and optional chaining.

    const user = { name: "Ada" };
    const { name } = user;
    user.profile?.email;
    • JavaScript objects
    • object properties
    • destructuring
    Study Objects
  8. Classes

    Create reusable object models with class syntax, constructors, methods, inheritance, static fields, and private fields.

    class User { constructor(name) { this.name = name; } }
    class Admin extends User {}
    • JavaScript classes
    • class syntax
    • inheritance
    Study Class basic syntax
  9. Modules

    Split JavaScript into files with named exports, default exports, and imports.

    export function format(value) { return String(value); }
    import { format } from "./format.js";
    • JavaScript modules
    • import export
    • ES modules
    Study Modules, introduction
  10. Promises and async/await

    Represent asynchronous results with promises and write promise flow clearly with async functions and await.

    const result = await fetchData();
    promise.then(handleResult).catch(handleError);
    • JavaScript promises
    • async await
    • asynchronous JavaScript
    Study Async/await
  11. DOM and events

    Select elements, update the page, and respond to user actions with browser event listeners.

    const button = document.querySelector("button");
    button.addEventListener("click", onClick);
    • JavaScript DOM
    • querySelector
    • event listener
    Study Event loop: microtasks and macrotasks
  12. Fetch and JSON

    Call APIs with fetch, parse JSON responses, stringify data, and handle network errors.

    const url = "/api/items";
    const data = await response.json();
    • JavaScript fetch
    • JSON parse
    • API request
    Study Fetch
  13. Regular expressions

    Search, validate, extract, and replace text with RegExp patterns and string methods.

    /\d+/.test(value);
    text.replace(/\s+/g, " ");
    • JavaScript regex
    • regular expression
    • RegExp
    Study Patterns and flags