Functions – Default Parameters, online

Six activities your students do on their own devices. See who's finished, and their scores.

Functions – Default Parameters in one minute

What students need to know

This is exactly what a default parameter does. Passing "Sam" replaces the default "Guest" value.

If no argument is given, the default value is used instead. Default parameters use = directly in the parameter list.

Mistakes students make

  • Default parameters use =, not ==, to assign the value.
  • Default parameters use =, not :, to assign the value.
  • Default parameters need an = before the value.
  • Don't add 'let' inside the parameter list.
PREVIOUS · MODULE 40Functions – Return Values
YOU ARE HERE · MODULE 41Functions – Default Parameters
NEXT · MODULE 42Arrow Functions

Discover other journeys with this module

What students will learn in this module

Every question in Module 41

Quick questions

  1. Does a default parameter provide a fallback value when no argument is passed?AYesBNo
  2. Is = used to assign a default value to a parameter?AYesBNo
  3. Is ':' a valid way to assign a default parameter value?AYesBNo
  4. Does passing an argument override a parameter's default value?ANoBYes
  5. Should 'let' be added before a parameter name in the list?ANoBYes

Key terms

Students type the meaning of:

  • =

Match the pairs

function greet(name = "Guest") { ... }Match it to what it does
function add(a, b = 0) { ... }Match it to what it does
Provides a fallback value when no argument is givenMatch it to what it does
Overrides the default value when an argument is passedMatch it to what it does
function add(a, b == 0) { ... }Match it to what it does
function mul(a, b: 1) { ... }Match it to what it does

Fill in the blanks

  1. function greet(name _ "Guest") {

    Hint: Type the symbol used to assign a default value to name.

  2. function add(a, b _ 0) {

    Hint: Type the symbol used to assign a default value to b.

  3. function power(base, exp = _) {

    Hint: Type the default value used for exp.

  4. function counter(step _ 1) {

    Hint: Type the symbol used to assign a default value to step.

  5. function scale(factor = _) {

    Hint: Type the default value used for factor.

Spot the error

Question 1

Afunction add(a, b == 0) {Bconsole.log(a + b);C}

Question 2

Afunction mul(a, b: 1) {Bconsole.log(a * b);C}

Question 3

Aconsole.log("hi");Bfunction greet(n "Al") {Cconsole.log(n);

Question 4

Aconsole.log("go");Bfunction power(let x = 2) {Cconsole.log(x);

Question 5

Alet a = 1;Bconsole.log(a);CFunction timer(s = 30) {Dconsole.log(s);