QUESTION 18 / 20 · FUNCTIONS · BEGINNER

The missing return

What will this code print? Read each line, then make your prediction.

Where this matters

This distinction matters in array callbacks: a calculation inside braces can run successfully while the callback still returns undefined.

JavaScript · read-only example
const first = n => n * 2;
const second = n => { n * 2; };
console.log(first(3));
console.log(second(3));
Your prediction

Read the full explanation

An expression arrow returns its expression. A block body needs return; without it, the function returns undefined.

Trace the code

  1. The first arrow has an expression body, so its expression value becomes the return value.
  2. The second has a block body. Evaluating multiplication alone does not return it.
  3. Reaching the end of that function without return produces undefined.

Why the other predictions differ

  • undefined undefined — The first expression arrow has an implicit return.
  • 6 6 — The second arithmetic expression is evaluated but never returned.
Expected console output
6
undefined

Reading this explanation does not record mastery. A correct submitted attempt can do so, including after review.

Change one thing

Keep the braces but add an explicit return.

Predict the result, then run this self-contained snippet in your browser’s developer console. It uses only sample values and makes no network requests.

const second = n => { return n * 2; }; console.log(second(3));
Check the variation’s output
6

Explain which binding, value, or operation changed before moving to the next challenge.