Amy M Haddad

How to Declare a JS Arrow Function⁠—My Recent freeCodeCamp Article

By: Amy M Haddad

image

If you find JavaScript’s arrow function syntax a bit confusing, you’re not alone. It can be tricky to nail down at first. And that’s why I want to let you know about my latest freeCodeCamp article.

Last week, I published an article for freeCodeCamp titled, Arrow Function JavaScript Tutorial – How to Declare a JS Function with the New ES6 Syntax. In this tutorial, I explain how to write an arrow function in JavaScript with the ES6 syntax.

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