logo
Published on

Arrow functions vs Regular functions

Authors
  • avatar
    Name
    Ganesh Negi
    Twitter

Arrow functions vs Regular functions

Arrow functions vs Regular functions

this binding

  • Regular function: Dynamic- Based on the caller.

  • Arrow function: lexical- inherits from the surrounding scope.

arguments object

  • Regular function: Has its own arguments.

  • Arrow function: Doesn't have own its own arguments.

constructor usage

  • Regular function: Can be used as a constructor (new)

  • Arrow function: Cannot be used as a constructor

super keyword

  • Regular function: Works with super in clasess

  • Arrow function: Doesn't bind super

Hoisting

  • Regular function: Hoisted with function declarations.

  • Arrow function: Not hoisted (like function expressions).

Use in objects

  • Regular function: Ideal for methods that need this.

  • Arrow function: Not suitable as object methods if this is used.

Use in callbacks

  • Regular function: Can be used , but less clean for inline logic.

  • Arrow function: Perfect for short, inline functions like .map()

Binding required

  • Regular function: May reuire .bind(this) in many cases.

  • Arrow function: Never needs manual binding.

Performance

  • Regular function: Slightly better in complex scenarios.

  • Arrow function: Similar, but cleaner for small, fast logic.