Course contentsShow
← JavaScript
Lesson 393 of 2,72311. FunctionsFree lesson

Single Expression Arrow Functions

Understand implicit returns when arrow functions contain a single expression without braces.

Single Expression Arrow Functions

You'll learn how arrow functions automatically return the result of a single expression without needing curly braces or the return keyword.

The Magic of Implicit Returns

When an arrow function contains just one expression (not a statement or multiple lines), you can skip the curly braces {} entirely. JavaScript will automatically return whatever that expression evaluates to. No return keyword needed!

// Traditional arrow function with explicit return
const double = (x) => {
  return x * 2;
};

// Single expression version - implicit return
const doubleShort = (x) => x * 2;

console.log(double(5));      // 10
console.log(doubleShort(5)); // 10

Both functions do exactly the same thing, but the second one is more concise.

Think of It Like This

Imagine the arrow (=>) literally points to what gets returned. If there's just one thing after the arrow and no curly braces wrapping it, that thing automatically comes back as the result.

const greet = name => `Hello, ${name}!`;
console.log(greet('Alex')); // "Hello, Alex!"

const add = (a, b) => a + b;
console.log(add(3, 7)); // 10

const isEven = num => num % 2 === 0;
console.log(isEven(4)); // true

Notice how clean this looks! The entire function fits on one readable line.

When You Need Curly Braces

If you add {}, you must explicitly write return again:

const subtract = (a, b) => { a - b };  // Returns undefined!
const correct = (a, b) => { return a - b }; // Works correctly

Key Takeaway: Arrow functions with a single expression (no curly braces) automatically return that expression's value—making your code shorter and cleaner for simple operations.