QUESTION 03 / 20 · FUNCTIONS · BEGINNER

A local total

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

Where this matters

Function parameters let a calculation use a caller’s value without needing to change the caller’s variable.

JavaScript · read-only example
let total = 5;
function double(total) { return total * 2; }
console.log(double(total));
console.log(total);
Your prediction

Read the full explanation

The parameter is a local binding initialized to five. Multiplication returns ten without assigning to the outer total.

Trace the code

  1. Calling double evaluates the outer total to 5 and initializes a separate local parameter with that number.
  2. The function returns 10. Returning a value does not assign that value to the outer total.
  3. The second log runs outside the function and reads the unchanged outer number.

Why the other predictions differ

  • 5 5 — The function does multiply its local parameter, so its return is ten.
  • 10 10 — Returning a computed number does not assign it to the outer variable.
Expected console output
10
5

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

Change one thing

Explicitly assign the return value to total. Compare this with merely logging the return value.

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.

let total = 5; function double(value) { return value * 2; } total = double(total); console.log(total);
Check the variation’s output
10

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