TetSharing
JavaScript tutorial · 19 chapters
  1. Get started
  2. let, const and var
  3. Data types
  4. Operators and equality
  5. Strings
  6. Template literals
  7. if, else and switch
  8. Loops
  9. Functions
  10. Arrow functions
  11. Arrays
  12. map, filter, reduce
  13. Objects
  14. Destructuring and spread
  15. Classes
  16. Errors and try...catch
  17. Promises
  18. async and await
  19. JSON

Final JavaScript quiz
Cheat sheet: javascript array methods

Chapter 10 of 19 · By Ethan Cole · Updated November 21, 2026

JavaScript Arrow Functions: Short Syntax and this

Arrow functions are a compact way to write functions, introduced in ES2015. They are everywhere in modern JavaScript, especially as short callbacks passed to array methods, timers and promises.

The syntax

const double = (n) => n * 2; is a function that takes n and returns n * 2. Compared with function, you drop the keyword, put => after the parameters, and, when the body is a single expression, you can drop the braces and the return too. This is called an implicit return.

  • With no parameters, write empty parentheses: () => 42.
  • With exactly one parameter the parentheses are optional, n => n * 2, though many style guides keep them.
  • With a block body in braces, you need an explicit return, just like a normal function.

Returning an object

() => { name: "Ava" } does not return an object: the braces are read as a block body, and name: becomes a label. Wrap object literals in parentheses: (name) => ({ name, active: true }). The { name } shorthand means { name: name }.

JavaScript · editable

Expected output

42 5
{name: "Ava", active: true}
[30, 10, 20]
3

Arrows as callbacks

nums.map((n) => n * 10) passes an arrow to map, which calls it once per item. This is where arrows shine: the logic sits right where it is used, with almost no syntax around it.

Arrows and this

Regular functions get their own this, decided by how they are called. Arrow functions do not; they use the this of the code around them. In the example, the arrow passed to forEach sits inside the start() method, so this.count refers to the counter object. With a regular function callback, this would not be the counter and the count would not change.

The flip side: do not use an arrow function as an object method that needs this to be the object, and arrows cannot be used with new as constructors.

Common mistakes

  • Returning an object without wrapping it in parentheses.
  • Adding braces and forgetting the return: (n) => { n * 2 } returns undefined.
  • Using an arrow as a method and expecting this to be the object.

Summary

  • (params) => expression returns the expression implicitly.
  • Use braces and return for multi-statement bodies.
  • Wrap returned object literals in parentheses.
  • Arrows inherit this from the surrounding code.

Quiz: Arrow functions

1. What does ((a, b) => a * b)(3, 4) return?

The arrow is called immediately and returns the product.

2. Why does () => { x: 1 } return undefined?

Wrap the object in parentheses: () => ({ x: 1 }).

3. Where does an arrow function get its this?

Arrow functions use lexical this.

Official docs

Written under the pen name Ethan Cole with AI-assisted drafting. Every code example on this page is executed by our test suite before publishing. Found a mistake? Tell us.