← JavaScript

Functions – Default Parameters

Assigns a default value to a parameter, used only when no argument is passed for it.

Understanding Functions – Default Parameters in JavaScript

What it does: 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. JavaScript uses =, not :, for default parameters. Any argument passed in takes priority over the default. Parameters are declared without let or const. Default values can be any valid JavaScript expression.

Common mistakes: Default parameters use =, not ==, to assign the value. Default parameters use =, not :, to assign the value.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 41–52) and word search (Modules 21–52).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Does a default parameter provide a fallback value when no argument is passed?
YesNo
Matches
function add(a, b == 0) { ... }
↓
Wrong - default parameters use =, not ==
Applying
Meanings
Term
=
Meaning
Assigns a default value to a parameter, used only when no argument is passed for it.
Practice
function greet(name = "Guest") {
Testing
Gaps
function greet(name "Guest") {
Check Answer
Spots
1function add(a, b == 0) {
2console.log(a + b);

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Sand Cat' badge — Precision Prowler, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Does a default parameter provide a fallback value when no argument is passed?
A. Yes ✓
B. No
If no argument is given, the default value is used instead.
2. Is = used to assign a default value to a parameter?
A. Yes ✓
B. No
Default parameters use = directly in the parameter list.
3. Is ':' a valid way to assign a default parameter value?
A. Yes
B. No ✓
JavaScript uses =, not :, for default parameters.
4. Does passing an argument override a parameter's default value?
A. No
B. Yes ✓
Any argument passed in takes priority over the default.
5. Should 'let' be added before a parameter name in the list?
A. No ✓
B. Yes
Parameters are declared without let or const.

Match the Pairs

function greet(name = "Guest") { ... } → Uses "Guest" as name if no argument is passed
function add(a, b = 0) { ... } → Uses 0 as b if no argument is passed for b
Provides a fallback value when no argument is given → name = "Guest"
Overrides the default value when an argument is passed → greet("Sam")
function add(a, b == 0) { ... } → Wrong - default parameters use =, not ==
function mul(a, b: 1) { ... } → Wrong - default parameters use =, not :

Key Term

=
Assigns a default value to a parameter, used only when no argument is passed for it.

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 = 2) {
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 = 5) {
Hint: Type the default value used for factor.

Spot the Error

Question 1
A function add(a, b == 0) {
B console.log(a + b);
C }
Line A — Default parameters use =, not ==, to assign the value.
Question 2
A function mul(a, b: 1) {
B console.log(a * b);
C }
Line A — Default parameters use =, not :, to assign the value.
Question 3
A console.log("hi");
B function greet(n "Al") {
C console.log(n);
Line B — Default parameters need an = before the value.
Question 4
A console.log("go");
B function power(let x = 2) {
C console.log(x);
Line B — Don't add 'let' inside the parameter list.
Question 5
A let a = 1;
B console.log(a);
C Function timer(s = 30) {
D console.log(s);
Line C — 'function' must be lowercase - a capital F causes an error.

Student with a class code? Join your class →