Emulate `arguments` object in JavaScript’s “fat” arrow functions

Attila Gulyas
Jul 23, 2017 · 1 min read

Arrow functions in JavaScript (unlike regular functions) do not have their own arguments object ¹ but they can be emulated with the spread operator:

const return_args = (...args) => argsreturn_args(7,"the cake is a lie",27)   //> [7,"the cake is a lie",27]

args is a regular Array with all of its pros and cons.

I learned this trick from this Stack Overflow answer.


Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade