← Back to the exercise

Arrow Functions and this

The answer to the exercise in Arrow Functions and this.

The braces after => made a body, and that body never returned anything. The body holds one expression, so the braces can go and the value comes back on its own. The arrow still remembers amount, so boostByOne adds 1.

function makeBooster(amount) {
  return (rating) => rating + amount; // was: (rating) => { rating + amount; }
}

const boostByOne = makeBooster(1);

console.log("Severance:", boostByOne(8.7));
console.log("Andor:", boostByOne(7.5));