Multiline Arrow Functions

Get introduced to multiline arrow functions and how they differ syntactically and semantically from anonymous functions.

Arrow functions are not restricted to having a single-line body. JavaScript permits arrow functions to be multiline.

Multiline arrow functions syntax

Multiline arrow functions are not as crisp, concise, and expressive as single-line arrow functions. The multiple lines in the body should be enclosed within {}. Additionally, each statement or expression is expected to end with ;, and if the body intends to return a value, the return keyword is required.

Multiline arrow vs multiline anonymous functions

Here’s a piece of code that computes a factorial defined as an anonymous function:

Get hands-on with 1200+ tech skills courses.