Lesson
Arrow functions
A function is a named recipe. You give it an input, it gives you an output. The short spelling is an arrow function.
function tagOf(visitor) {
return visitor.slice(0, 4);
}
const tagOf = (visitor) => visitor.slice(0, 4);Both mean: take visitor, give back the first four characters. (visitor) => is the input. What comes after the arrow is the result.
The same shape works on a number:
const double = (n) => n * 2; double(4) // 8
The town uses these as callbacks: lots.map((lot) => ...) and onClick={() => setVisits(visits + 1)}.