What is an arrow function in JavaScript?
Answer
Arrow functions (ES6) provide a shorter syntax for writing functions: (params) => expression or (params) => { statements }. Single parameter: x => x * 2. The key difference from regular functions is how they handle this: arrow functions do NOT have their own this — they inherit this lexically from the enclosing scope where they are defined. This makes them ideal for callbacks inside methods (where you want to preserve the outer this). Arrow functions also do not have arguments object, cannot be used as constructors (no new), and cannot be used as generators. They should NOT be used for: object methods (if you need this to refer to the object), event handlers that need dynamic this, or prototype methods. Implicit return: single-expression arrows return without the return keyword.
Previous
What is the difference between function declaration and function expression?
Next
What is the this keyword in JavaScript?