foundation

Arrow functions

Lexical this, concise syntax, missing arguments object, and when arrows are the wrong tool.

Arrow functions are concise and lexically bind `this`, `arguments`, `super`, and `new.target`. They suit callbacks that should not define a receiver. They are poor object methods when `this` must be dynamic.

Arrows have no own `arguments` object and cannot be used as constructors. Concise bodies returning object literals need parentheses: `() => ({ id: 1 })`.

Use arrows in React event handlers when lexical `this` is desired; avoid them as class methods that callers may extract.

On interviews, explain the concept with a concrete example and name the runtime behavior interviewers probe.

Common pitfalls include mixing similar APIs and forgetting edge cases during live coding.

The trade-off is often clarity versus performance or safety versus convenience.

Checklist:

  • Use for lexical this in callbacks.
  • Avoid as methods needing dynamic this.
  • Wrap returned object literals in parentheses.