devnotes.

Arrow Functions and Default Parameters

Arrow functions (ES2015) offer a shorter syntax and, importantly, don't have their own this.

const add = (a, b) => a + b;
const square = n => n * n;
const greet = (name = "Guest") => `Hello, ${name}`;

const sum = (...nums) => nums.reduce((total, n) => total + n, 0);
sum(1, 2, 3); // 6

Arrow functions inherit this from the surrounding (lexical) scope instead of binding their own, which is why they're preferred inside callbacks — like array methods or event handlers — where you want this to stay whatever it was outside the callback, rather than becoming undefined or the calling object.

Default parameters (name = "Guest") kick in only when an argument is undefined — passing null or 0 explicitly does not trigger the default. Combined with the rest parameter (...nums), functions can accept a flexible, well-typed number of arguments without needing the old arguments object.