Cheat Sheets
Functions · Study material
JavaScript Functions Cheat Sheet
| Code | Meaning |
|---|---|
function f(a, b) { return a + b; } | declaration (hoisted) |
const f = function (a) { … }; | function expression |
const f = (a) => a * 2; | arrow with implicit return |
() => ({ id: 1 }) | arrow returning an object |
function f(x = 10) | default (for undefined only) |
function f(...rest) | rest parameter (last) |
f(...arr) | spread array into arguments |
f.length · f.name | params before default/rest · name |
(function () { … })(); | IIFE |
arr.map(fn) vs arr.map(fn()) | pass the function, not its result |
| no return | undefined |