return versus console.log inside a function
Hands a value back to the code that called the function so it can be stored or used. console.log only shows a value in the console, so a function that only logs gives back undefined.
Understanding return versus console.log inside a function in ACARA Digital Technologies Years 7–8
What it does: total only gets the answer 5 if add returns it. Logging alone would leave total as undefined. The function's job is to display a value, not to hand it back, so console.log is the right tool. add only logs the sum. It has no return, so the call gives back undefined. The 5 is shown in the console but is not stored. return ends the function straight away. Any code after it in the function is skipped. return hands 25 back, but nothing stores or displays it, so the student sees no output.
Common mistakes: A function body must open with a curly brace {, not a bracket (. The line should be function add(a, b) {. Then return a + b can hand the sum back to the caller. console.log only shows the value in the console. It does not give it back, so result would be undefined. The line should be return n * n; so the value goes back to the caller.
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 611–623) and word search (Modules 611–634).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
returnFill in the Blanks
Spot the Error
Student with a class code? Join your class →