JavaScript Complete Cheatsheet & Notes
Syntax Basics
let,const,var— variable declarations// commentor/* 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;argumentsobject 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.nameorobj["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...whilebreak/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 scopingTemplate Literals—`Hello ${name}`Destructuring—const {a,b} = obj;Spread—arr2 = [...arr]Rest Params—function(...args)Modules—export / importClasses—class Person { constructor() {} }
Async JavaScript
setTimeout(fn, 1000)setInterval(fn, 500)Promise—new Promise((res, rej) => ...)async/awaitfetch("url").then(res => res.json())try...catchfor error handling
Browser APIs
localStorage.setItem("key", "value")localStorage.getItem("key")navigator.geolocation.getCurrentPosition()fetch()APIhistory.pushState()