JavaScript Cheatsheet

Comprehensive reference for JavaScript fundamentals, ES6+, arrays, objects, and async operations.

KeywordDescriptionSyntaxExampleCategory
constDeclare block-scoped constant variableconst name = valueconst PI = 3.14159Variables
letDeclare block-scoped variablelet name = valuelet count = 0Variables
varDeclare function-scoped variable (legacy)var name = valuevar x = 10Variables
functionDeclare a functionfunction name(params) { ... }function add(a, b) { return a + b; }Functions
Arrow FunctionES6 concise function syntaxconst name = (params) => { ... }const add = (a, b) => a + bFunctions
Default ParametersSet default function parametersfunction name(param = default) { ... }function greet(name = "Guest") { ... }Functions
Rest ParametersCapture remaining function argumentsfunction name(...args) { ... }function sum(...nums) { return nums.reduce((a,b) => a+b) }Functions
Spread OperatorExpand iterable into individual elements...iterableconst arr = [...[1,2,3], 4]ES6+
DestructuringExtract values from objects/arraysconst { x, y } = objconst { name, age } = userES6+
Template LiteralsCreate strings with expressions`string ${expression}``Hello, ${name}!`ES6+
map()Transform array elementsarray.map(callback)[1,2,3].map(x => x * 2)Arrays
filter()Filter array elementsarray.filter(callback)[1,2,3].filter(x => x > 1)Arrays
reduce()Reduce array to single valuearray.reduce(callback, initial)[1,2,3].reduce((sum, x) => sum + x, 0)Arrays
forEach()Iterate over array elementsarray.forEach(callback)[1,2,3].forEach(x => console.log(x))Arrays
find()Find first element matching conditionarray.find(callback)[1,2,3].find(x => x > 2)Arrays
Object.keys()Get object property namesObject.keys(obj)Object.keys({a: 1, b: 2})Objects
Object.values()Get object property valuesObject.values(obj)Object.values({a: 1, b: 2})Objects
Object.entries()Get key-value pairsObject.entries(obj)Object.entries({a: 1, b: 2})Objects
PromiseHandle asynchronous operationsnew Promise((resolve, reject) => {})new Promise(r => setTimeout(() => r("done"), 1000))Async
async/awaitSimplified promise handlingasync function() { await promise }const data = await fetch("/api")Async
try/catchError handling in async codetry { ... } catch(e) { ... }try { await fetch() } catch(e) { console.error(e) }Async