All Cheat Sheets
JS

JavaScript Cheat Sheet

Variables & Data Types

letBlock-scoped mutable variable
let count = 0;
count += 1;
constBlock-scoped constant
const PI = 3.14;
const name = "Mishu";
Primitive typesstring, number, boolean, null, undefined, symbol
const str = "hello";
const num = 42;
const bool = true;
TypeofReturns the type of a value
typeof "hello" // "string"
typeof 42      // "number"

Functions

Function declarationStandard function
function greet(name) {
  return `Hello, ${name}!`;
}
Arrow functionConcise function syntax
const add = (a, b) => a + b;
Default paramsParameters with defaults
function multiply(a, b = 1) {
  return a * b;
}
Rest paramsVariable number of arguments
function sum(...nums) {
  return nums.reduce((a, b) => a + b, 0);
}

Arrays & Objects

Array literalCreate an array
const arr = [1, 2, 3];
Array methodsCommon operations
arr.map(x => x * 2);
arr.filter(x => x > 1);
arr.reduce((a, b) => a + b, 0);
arr.find(x => x === 2);
Object literalCreate an object
const obj = {
  key: "value",
  method() { return this.key; }
};
DestructuringUnpack values
const { name, age } = person;
const [first, second] = arr;
Spread operatorSpread iterable into elements
const copy = [...arr];
const merged = { ...obj1, ...obj2 };

Control Flow

If-elseConditional execution
if (x > 0) {
  console.log("positive");
} else {
  console.log("not positive");
}
Loopfor, while, do-while
for (let i = 0; i < 5; i++) { ... }
while (condition) { ... }
SwitchMulti-way branch
switch (day) {
  case 1: return "Mon";
  case 2: return "Tue";
  default: return "Unknown";
}
TernaryInline conditional
const result = x > 0 ? "yes" : "no";