Arrow Functions and Functional Style
The fluency of single-line arrow functions truly shines in the functional style of programming. In this style of programming, we use function composition—a series of transformations—to make the code expressive and easier to maintain. Functional style code removes accidental complexity that’s present in the imperative style of programming.
Let’s explore this with a few examples. Suppose we’re given a list of names and asked to create a comma-separated result string with names of length five, all in uppercase. Try implementing that code using the traditional for loop. It’s a simple problem but not a simple solution—that’s accidental complexity. Here’s an imperative implementation:
| const pickNamesInUpperCaseOfLength ... |
Get Rediscovering JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.