Arrow functions are a concise syntax for writing functions introduced in ES6. They are especially popular for short one-liners and callbacks.
// Traditional function expression
const add = function(a, b) { return a + b; };
// Arrow function — same result
const add = (a, b) => a + b;
// Single parameter — parentheses optional
const double = n => n * 2;
// No parameters — empty parentheses required
const greet = () => "Hello!";
// Multi-line body — needs {} and explicit return
const classify = n => {
if (n > 0) return "positive";
if (n < 0) return "negative";
return "zero";
};
this — they inherit this from the surrounding scope (important in OOP, covered later).arguments object.square(n) that returns n * n.celsius(f) that converts Fahrenheit to Celsius: (f - 32) * 5/9, rounded to 1 decimal place (Math.round(value * 10) / 10).isEven(n) that returns true if n is even, false otherwise.#output: "5² = 25 | 98°F = 36.7°C | 4 is even: true".Arrow function: const fn = (params) => expression;