Arrow Functions
What is the output of this code that accesses 'arguments' in an arrow function?
const fn = () => arguments;
console.log(fn(1, 2, 3));
This code will result in a ReferenceError: arguments is not defined (assuming this is running at the global scope). Arrow functions don't have their own `arguments` object, unlike regular functions. Instead, arrow functions inherit the `arguments` object from their enclosing lexical scope. When the arrow function is defined in the global scope, there is no `arguments` object to inherit, resulting in a ReferenceError when trying to access it. If this same arrow function were defined inside a regular function, it would access that function's `arguments` object. For example: `function outer() { const fn = () => arguments; return fn(); } console.log(outer(1, 2, 3));` would log the `arguments` object from `outer`. When working with arrow functions, it's generally better to use rest parameters instead of `arguments` for better clarity and to avoid these pitfalls: `const fn = (...args) => args;`. This creates a true array containing all arguments, which is easier to work with than the array-like `arguments` object.