🟨 JavaScript Cheatsheet
A one-page reference for modern JavaScript (ES2020+). Press Ctrl + P to save as PDF — the print stylesheet hides everything except the code.
Variables
javascript
let x = 42; // mutable
const PI = 3.14; // immutable binding
// Don't use var in modern codeStrings
javascript
const name = 'Aisha';
`Hello, ${name}` // template literal
name.toUpperCase()
name.toLowerCase()
name.includes('isha')
name.replace('A', 'B')
name.split(',')
['a','b'].join(',')
name.trim()Arrays
javascript
const xs = [1, 2, 3];
xs.push(4); // [1,2,3,4]
xs.pop();
xs[0]; xs.at(-1);
xs.length
xs.slice(1, 3)
xs.map(n => n * 2)
xs.filter(n => n > 1)
xs.reduce((a, b) => a + b, 0)
xs.find(n => n > 2)
[...xs] // shallow copyObjects
javascript
const user = { name: 'Aisha', age: 30 };
user.name; user['age'];
user.role = 'admin';
Object.keys(user); Object.values(user); Object.entries(user);
'age' in user
delete user.age;
const { name, age } = user; // destructure
const copy = { ...user }; // shallow copyConditionals
javascript
if (cond) { ... } else if (cond2) { ... } else { ... }
// Ternary
const status = age >= 18 ? 'adult' : 'minor';
// Switch
switch (day) {
case 'Sat':
case 'Sun': console.log('weekend'); break;
default: console.log('weekday');
}Loops
javascript
for (let i = 0; i < 5; i++) { ... }
for (const x of xs) { ... }
for (const k in obj) { ... }
while (cond) { ... }
xs.forEach((x, i) => { ... });Functions
javascript
function greet(name, greeting = 'Hello') {
return `${greeting}, ${name}!`;
}
const greet = (name) => `Hello, ${name}!`;
// Rest / spread
function sum(...nums) { return nums.reduce((a,b) => a+b, 0); }Async
javascript
async function getUser(id) {
const r = await fetch(`/users/${id}`);
return r.json();
}
try {
const u = await getUser(1);
} catch (e) {
console.error(e);
}Classes
javascript
class User {
constructor(name) { this.name = name; }
greet() { return `Hi, ${this.name}`; }
}
class Admin extends User { ... }
const u = new User('Aisha');📌
Need the concepts?
This is a syntax reference, not a tutorial. Each row maps to a concept lesson — start with the 13 concepts if anything here is unfamiliar.