← ACARA Digital Technologies Years 9–10

Functions that return true or false (JavaScript)

A function that returns true or false can be called right inside an if condition. The if block runs only when the function returns true, like isEven(n) or isValidAge(age).

Understanding Functions that return true or false (JavaScript) in ACARA Digital Technologies Years 9–10

What it does: The comparison and && produce a Boolean, so the function returns it directly without needing an if/else. isEven(n) gives back true or false, so it works as the condition without writing === true. The condition is false, so the if block is skipped. Boolean functions are often named with is, such as isEven or isValidAge, so the call reads like a yes/no question. Without brackets and an argument, isEven is just the function itself and is never called. Always call it as isEven(n). Without return, the comparison result is thrown away. It should be return n % 2 === 0;.

Common mistakes: Dividing by 2 does not test for an even number. Use the remainder operator: return n % 2 === 0; so the function returns true only for even numbers. With || the function returns true for almost any number, so invalid ages pass the if check. Both conditions must hold, so use &&: return age > 0 && age < 120;.

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 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.

Learning
Duo
Which function returns a Boolean?
function isEven(n) { return n % 2 === 0; }function double(n) { return n * 2; }
Matches
function isEven(n) { n % 2 === 0; }
↓
The function never uses return, so it gives back undefined instead of true or false and the if block never runs
Applying
Meanings
Term
if (isValidAge(age))
Meaning
A function that returns true or false can be called right inside an if condition. The if block runs only when the function returns true, like isEven(n) or isValidAge(age).
Practice
function isValidAge(age) {
Testing
Gaps
function isEven(n) { return n 2 === 0; }
Check Answer
Spots
1function isEven(n) {
2 return n / 2 === 0;

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

The 'Snow Leopard' badge — Silent Debugger, 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. Which function returns a Boolean?
A. function double(n) { return n * 2; }
B. function isEven(n) { return n % 2 === 0; } ✓
isEven returns the result of a comparison, which is true or false. double returns a number.
2. Which is the correct way to use a Boolean function in an if statement?
A. if (isValidAge(age)) { ... } ✓
B. if (isValidAge(age) === true === ) { ... }
The call isValidAge(age) already gives true or false, so it can sit directly inside the brackets as the condition.
3. isEven(4) returns true. What happens in: if (isEven(4)) { console.log('Even'); }
A. Nothing is printed
B. 'Even' is printed ✓
The if block runs when the condition is true. isEven(4) is true, so the message is printed.
4. isValidAge(200) returns false. What happens in: if (isValidAge(200)) { console.log('OK'); }
A. Nothing is printed ✓
B. 'OK' is printed
The condition is false, so the if block is skipped.
5. Which function would work as an if condition?
A. function isValidAge(age) { return age >= 0 && age <= 120; } ✓
B. function isValidAge(age) { console.log(age >= 0 && age <= 120); }
The second function only logs the result and returns undefined, which is falsy. The first one returns a Boolean the if statement can use.

Match the Pairs

function isEven(n) { return n % 2 === 0; } → A function that returns true when n is even and false when it is odd
if (isValidAge(age)) { console.log('OK'); } → Calls isValidAge and runs the block only if it returns true
A function can return the result of a comparison, which is already true or false → function isValidAge(age) { return age >= 0 && age <= 120; }
A Boolean-returning function call can be used by itself as an if condition → if (isEven(n)) { console.log('even'); }
function isEven(n) { n % 2 === 0; } → The function never uses return, so it gives back undefined instead of true or false and the if block never runs
if (isValidAge) { console.log('OK'); } → The function is not called because the brackets and argument are missing, so the condition is the function itself, which is always truthy

Key Term

if (isValidAge(age))
A function that returns true or false can be called right inside an if condition. The if block runs only when the function returns true, like isEven(n) or isValidAge(age).

Fill in the Blanks

1. function isEven(n) { return n % 2 === 0; }
Hint: Type the operator that gives the remainder after division.
2. function isValidAge(age) { return age >= 0 && age <= 120; }
Hint: Type the logical operator that needs both conditions to be true.
3. if (isEven(n)) { console.log("even"); }
Hint: Type the keyword that runs a block only when its condition is true.
4. function isValidAge(age) { return age >= 13; }
Hint: Type the keyword that sends the true or false result back to the caller.
5. const n = 7; if (!isEven(n)) console.log("odd");
Hint: Type the operator that flips true to false, so the block runs for odd numbers.

Spot the Error

Question 1
A function isEven(n) {
B return n / 2 === 0;
C }
D if (isEven(6)) {
E console.log("Even");
F }
Line B — Dividing by 2 does not test for an even number. Use the remainder operator: return n % 2 === 0; so the function returns true only for even numbers.
Question 2
A function isValidAge(age) {
B return age > 0 || age < 120;
C }
D if (isValidAge(15)) {
E console.log("Valid");
F }
Line B — With || the function returns true for almost any number, so invalid ages pass the if check. Both conditions must hold, so use &&: return age > 0 && age < 120;
Question 3
A function isValidAge() {
B return age >= 18;
C }
D if (isValidAge(20)) {
E console.log("Allowed");
F }
Line A — The function needs a parameter to receive the age. Without it, age is not defined inside the function. The line should be function isValidAge(age) {
Question 4
A function isValidAge(age) {
B return age >= 13;
C }
D if (isValidAge) {
E console.log("Valid");
F }
Line D — This names the function but never calls it. A function name on its own is always truthy. Call it with a value: if (isValidAge(14)) {
Question 5
A const isValidAge = (age) -> {
B return age >= 16;
C }
D if (isValidAge(17)) {
E console.log("Valid");
F }
Line A — JavaScript arrow functions use => and not ->. The line should be const isValidAge = (age) => {

Student with a class code? Join your class →