What's the output?
const add = x => y => z => {
console.log(x, y, z);
return x + y + z;
};
add(4)(5)(6);You missed this one before
The add function returns an arrow function, which returns an arrow function, which returns an arrow function (still with me?). The first function receives an argument x with the value of 4. We invoke the second function, which receives an argument y with the value 5. Then we invoke the third function, which receives an argument z with the value 6. When we're trying to access the value x, y and z within the last arrow function, the JS engine goes up the scope chain in order to find the values for x and y accordingly. This returns 4 5 6.
Question 123 · see the original (opens in a new tab)
or press Enter