A function with no return gives undefined
The value a function gives back when it has no return statement. console.log only shows a value on screen, so a variable storing the result will hold undefined.
Understanding A function with no return gives undefined in ACARA Digital Technologies Years 9–10
What it does: The return keyword sends n * 2 back to wherever the function was called, so it can be stored or used. greet does a job (printing) and does not need to give a value back, so it quietly returns undefined. greet() prints Hi on screen, but it has no return. So result holds undefined, not the text. There is no return, so square(4) is undefined. Adding 1 to undefined gives NaN. Fix it with return n * n;. The expression a + b is calculated but never returned, so the function call gives back undefined.
Common mistakes: Once the arrow function has curly braces, it needs an explicit return. Without one it gives back undefined, so result holds undefined. It should be const sq = n => n * n; or { return n * n; }. console.log only shows the message on screen, it does not give a value back. The function never reaches a return, so text stores undefined. Line 3 should be return msg;.
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 681–707) and word search (Modules 629–707).
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
undefinedFill in the Blanks
Spot the Error
Student with a class code? Join your class →