JavaScript Arrow Functions

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

Arrow functions are a concise way of writing anonymous, lexically scoped functions in ECMAScript 2015 (ES6).

Syntax

  • x => y // Implicit return

  • x => { return y } // Explicit return

  • (x, y, z) => { ... } // Multiple arguments

  • async () => { ... } // Async arrow functions

  • (() => { ... })() // Immediately-invoked function expression

  • const myFunc = x

    => x*2 // A line break before the arrow will throw a 'Unexpected token' error

  • const myFunc = x =>

    x*2 // A line break after the arrow is a valid syntax

Remarks

For more information on functions in JavaScript, please view the Functions documentation.

Arrow functions are part of the ECMAScript 6 specification, so browser support may be limited. The following table shows the earliest browser versions that support arrow functions.

ChromeEdgeFirefoxInternet ExplorerOperaOpera MiniSafari
451222Currently unavailable32Currently unavailable10


Got any JavaScript Question?