All Cheat Sheets
JS
JavaScript Cheat Sheet
Variables & Data Types
letBlock-scoped mutable variablelet count = 0;
count += 1;constBlock-scoped constantconst PI = 3.14;
const name = "Mishu";Primitive typesstring, number, boolean, null, undefined, symbolconst str = "hello";
const num = 42;
const bool = true;TypeofReturns the type of a valuetypeof "hello" // "string"
typeof 42 // "number"Functions
Function declarationStandard functionfunction greet(name) {
return `Hello, ${name}!`;
}Arrow functionConcise function syntaxconst add = (a, b) => a + b;Default paramsParameters with defaultsfunction multiply(a, b = 1) {
return a * b;
}Rest paramsVariable number of argumentsfunction sum(...nums) {
return nums.reduce((a, b) => a + b, 0);
}Arrays & Objects
Array literalCreate an arrayconst arr = [1, 2, 3];Array methodsCommon operationsarr.map(x => x * 2);
arr.filter(x => x > 1);
arr.reduce((a, b) => a + b, 0);
arr.find(x => x === 2);Object literalCreate an objectconst obj = {
key: "value",
method() { return this.key; }
};DestructuringUnpack valuesconst { name, age } = person;
const [first, second] = arr;Spread operatorSpread iterable into elementsconst copy = [...arr];
const merged = { ...obj1, ...obj2 };Control Flow
If-elseConditional executionif (x > 0) {
console.log("positive");
} else {
console.log("not positive");
}Loopfor, while, do-whilefor (let i = 0; i < 5; i++) { ... }
while (condition) { ... }SwitchMulti-way branchswitch (day) {
case 1: return "Mon";
case 2: return "Tue";
default: return "Unknown";
}TernaryInline conditionalconst result = x > 0 ? "yes" : "no";