JavaScript Complete Cheatsheet & Notes

Syntax Basics

  • let, const, var — variable declarations
  • // comment or /* multi-line */
  • Case-sensitive & semicolon optional
  • console.log("Hello") — print output
  • Block scope: { ... }

Data Types

  • Primitive: string, number, boolean
  • null, undefined, symbol, bigint
  • Reference: object, array, function
  • typeof — returns variable type

Operators

  • +, -, *, /, %
  • === (strict equality) vs ==
  • >, <, >=, <=
  • ! (not), && (and), || (or)
  • +=, -= — assignment shortcuts
  • ++, -- — increment/decrement
  • ? ternary: condition ? a : b

Functions

  • function greet() { return "Hi" }
  • const sum = (a, b) => a + b;
  • arguments object for traditional functions
  • Default params: (x = 5)
  • Anonymous / Arrow / Callback functions

Arrays & Objects

  • const arr = [1, 2, 3];
  • arr.push(4); arr.pop();
  • arr.map(x => x * 2)
  • arr.filter(x => x > 2)
  • const obj = { name: "John", age: 25 };
  • obj.name or obj["age"]
  • Destructuring: const {name} = obj;

Control Flow

  • if (x > 5) { ... } else { ... }
  • switch(value) { case 1: ... break; }
  • for (let i=0; i<5; i++)
  • while(condition), do...while
  • break / continue

DOM Manipulation

  • document.getElementById("id")
  • document.querySelector(".class")
  • element.textContent = "Hello"
  • element.classList.add("active")
  • element.addEventListener("click", fn)

ES6+ Features

  • let, const — block scoping
  • Template Literals`Hello ${name}`
  • Destructuringconst {a,b} = obj;
  • Spreadarr2 = [...arr]
  • Rest Paramsfunction(...args)
  • Modulesexport / import
  • Classesclass Person { constructor() {} }

Async JavaScript

  • setTimeout(fn, 1000)
  • setInterval(fn, 500)
  • Promisenew Promise((res, rej) => ...)
  • async / await
  • fetch("url").then(res => res.json())
  • try...catch for error handling

Browser APIs

  • localStorage.setItem("key", "value")
  • localStorage.getItem("key")
  • navigator.geolocation.getCurrentPosition()
  • fetch() API
  • history.pushState()