Expression body
value => value * 2 returns the expression automatically.
Arrow functions are compact function expressions. They are excellent for callbacks and small transformations, but they have different this behavior.
const numbers = [1, 2, 3]; const doubled = numbers.map((value) => value * 2); console.log(doubled);
Functions & Scope
An arrow function is a shorter function expression using =>. It can have an expression body that returns automatically, or a block body that needs an explicit return.
Arrow functions do not create their own this, arguments, super or new.target. That makes them great for callbacks, but not a replacement for every method.
Use arrows when the function is small and value-oriented. Use normal functions when you need a method with its own this or when a declaration reads better.
value => value * 2 returns the expression automatically.
Use braces when the function needs multiple statements.
Arrow functions use this from the surrounding scope.
Array methods and event-adjacent helpers often use arrows.
Examples
const numbers = [1, 2, 3]; const doubled = numbers.map((number) => number * 2);
const panel = {
title: "Dashboard",
show: () => this.title
};
// Arrow functions do not create their own this.
Code patterns
These examples focus on syntax you will actually look up later: declarations, callbacks, returns, closures and context handling. Use the small patterns first, then study the deeper explanation.
Parentheses can be omitted for one simple parameter.
const double = value => value * 2; console.log(double(4));
Use parentheses for multiple inputs.
const add = (a, b) => a + b; console.log(add(2, 3));
Use return when braces are used.
const format = (value) => {
const clean = value.trim();
return clean.toUpperCase();
};
Arrows are very readable in simple array transformations.
const labels = ["html", "css", "js"]; const upper = labels.map((label) => label.toUpperCase()); console.log(upper);
Rules that matter
Functions are where JavaScript stops being a list of statements and becomes a system. Scope decides what each function can see, while return values and parameters decide how functions communicate.
map, filter and simple event helpers often read well with arrows.
Braces remove the implicit return.
Use method syntax instead.
Long one-liners become hard to scan.
Parentheses around one parameter are optional, but often consistent.
Use rest parameters instead of arguments in arrow functions.
Production thinking
Arrow functions reduce noise in callback-heavy JavaScript, but only when their this behavior matches the job.
UI code often uses callbacks. Clear arrow functions help keep event-driven behavior reviewable.
Production code should not use arrows blindly. Pick normal functions when this, methods or readability require it.
Array callbacks that render content should stay small enough to trust and test.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Functions only become useful when you can explain what goes in, what comes out and which scope the function can see.