How to Declare a JS Arrow Function—My Recent freeCodeCamp Article
By: Amy M Haddad
I tackle the questions most programmers want to know. When do you use parentheses? What about the return keyword and curly brackets? What is an arrow function exactly, anyway?
I also point out some nuances to be aware of when writing arrow functions with rest parameters and destructuring, for example. And I explain how to return an object literal expression with an arrow function.
A great way to understand arrow functions is through examples, which you'll find many of. That way, you can train your mind and eye to spot the differences.
“You’ve probably seen arrow functions written a few different ways,” I write at the start of the article. “Some have parentheses around the parameters, while others don’t. Some use curly brackets and the return keyword, others don’t. One even spans multiple lines, while the others consist of a single line.”
I then pose this question: “How do you know which arrow function syntax to use?” By the end of the article, you’ll be able to answer this question for a variety of situations.
Check it out to learn more.
← back to all posts