Get the latest tech news

What's the difference between named functions and arrow functions in JavaScript?


Arrow functions (also known as ‘rocket’ functions) are concise and convenient. However, they have subtle differences compared to function declarations and function expressions. So how do you know which one to use, and when?

If we compress the function body to one expression, we can drop the curly braces and the return keyword. We can also drop the round braces if the arrow function takes a single argument. We can use what we’ve learned to create a flow chart that will help us determine which function syntax to use.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of javascript

javascript

Photo of difference

difference

Photo of arrow functions

arrow functions

Related news:

News photo

Build a Sentence-Level Text-to-Speech Reader in JavaScript

News photo

If you're building a JavaScript library and need logging, you would love LogTape

News photo

JavaScript broke the web (and called it progress)