bhylu.com

Advertisements

Function Quiz

Predict a function result before running it. Distinguish a default parameter from an argument supplied explicitly.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

Before you run it

Write down the result you expect and explain which line produces it. Then run the example and compare your reasoning with the result below.

A practical example

JavaScript

function fee(amount = 5) {
  return amount * 2;
}
console.log(fee(), fee(0));

What happens

The answers are 10 and 0. Explain why zero does not use the default.