← ACARA Digital Technologies Years 9–10

A method inside an object literal

A method is a function stored as an object property. Write it inside the object, then call it with a dot and brackets: person.greet().

Understanding A method inside an object literal in ACARA Digital Technologies Years 9–10

What it does: jump() { ... } sits inside the object literal braces, so it is a method of player. A method needs brackets after its name, like greet(), before the curly braces that hold its code. Brackets run the method. Without them you only get the function itself and nothing happens. Write the object first, then a dot, then the method name: object.method(). The method uses return, so calling cat.speak() gives back the string 'Meow'. A method is called on its object with a dot, so use car.start().

Common mistakes: A method needs brackets after its name, just like a function. It should be bark() { return "Woof"; }. Inside a method, properties of the object must be reached with this. Plain word does not exist, so it should be this.word.

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 728–742) and word search (Modules 710–742).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which object literal correctly defines a method called greet?
const person = { greet { console.log('Hi'); } };const person = { greet() { console.log('Hi'); } };
Matches
const cat = { meow() { console.log('Meow'); } }; cat.meow;
↓
The brackets are missing, so the method is not called. It only refers to the function and nothing runs. Fix: cat.meow();
Applying
Meanings
Term
greet() { ... }
Meaning
A method is a function stored as an object property. Write it inside the object, then call it with a dot and brackets: person.greet().
Practice
const person = {
Testing
Gaps
console.log(petspeak());
Check Answer
Spots
2 name: "Rex",
3 bark { return "Woof"; }

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

The 'Wolverine' badge — Fearless Coder, 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 object literal correctly defines a method called greet?
A. const person = { greet() { console.log('Hi'); } }; ✓
B. const person = { greet { console.log('Hi'); } };
A method needs brackets after its name, like greet(), before the curly braces that hold its code.
2. Which line correctly calls the greet method on the person object?
A. person.greet;
B. person.greet(); ✓
Brackets run the method. Without them you only get the function itself and nothing happens.
3. What is a method?
A. A variable that stores only numbers
B. A function stored as a property of an object ✓
A method is just a function that lives inside an object as one of its properties.
4. Which call uses the dot correctly to run a method?
A. dog.bark() ✓
B. bark.dog()
Write the object first, then a dot, then the method name: object.method().
5. How is a method different from a plain function?
A. A method belongs to an object and is called with object.method() ✓
B. A method is called by writing just its name, like greet()
A plain function is called by its name alone. A method is called through the object that holds it.

Match the Pairs

const dog = { speak() { console.log('Woof!'); } }; → Creates an object literal with a method called speak stored inside it
dog.speak(); → Calls the speak method on the dog object
A method is a function stored as a property of an object, so it is written inside the object's curly braces → const player = { jump() { return 'Up!'; } };
A plain function is called by its name alone, but a method must be called with the object name, a dot and brackets → player.jump();
const cat = { meow() { console.log('Meow'); } }; cat.meow; → The brackets are missing, so the method is not called. It only refers to the function and nothing runs. Fix: cat.meow();
const cat = { meow() { console.log('Meow'); } }; meow(); → The method is called like a plain function. It belongs to cat, so it needs the dot: cat.meow();

Key Term

greet() { ... }
A method is a function stored as an object property. Write it inside the object, then call it with a dot and brackets: person.greet().

Fill in the Blanks

1. const pet = { speak() { return "Woof"; } }; console.log(pet.speak());
Hint: Type the symbol that joins the object name to its method when you call it.
2. const pet = { speak() { return "Woof"; } }; console.log(pet.speak());
Hint: Type the method name that the call below uses.
3. const user = { name: "Mia", hello() { return "Hi " + this.name; } };
Hint: Type the keyword that lets a method refer to its own object.
4. const maths = { triple(n) { return n * 3; } };
Hint: Type the keyword that sends a value back from the method.
5. const calc = { double(n) { return n * 2; } }; console.log(calc.double(4));
Hint: Type the name of the method defined in the object above.

Spot the Error

Question 1
A const dog = {
B name: "Rex",
C bark { return "Woof"; }
D };
E console.log(dog.bark());
Line C — A method needs brackets after its name, just like a function. It should be bark() { return "Woof"; }.
Question 2
A const cat = {
B name: "Mia",
C word: "Meow",
D say() { return word; }
E };
Line D — Inside a method, properties of the object must be reached with this. Plain word does not exist, so it should be this.word.
Question 3
A const car = {
B go() { return "Vroom"; }
C };
D console.log(car.go);
Line D — Without brackets the method is not called. It just refers to the function itself. It should be car.go().
Question 4
A const user = {
B name: "Sam"
C hello() { return "Hi"; }
D };
E console.log(user.hello());
Line B — Members of an object literal are separated by commas, including before a method. It should be name: "Sam",
Question 5
A const pet = [
B name: "Bo",
C speak() { return "Hi"; }
D };
E console.log(pet.speak());
Line A — An object literal with methods is wrapped in curly braces, not square brackets. It should be const pet = {.

Student with a class code? Join your class →