All subjects · Information Technology · WIT12 3 hour practical exam on web development with HTML, CSS and JavaScript
Subprograms (functions) and object orientation in JavaScript
Edexcel IAL Information Technology · WIT12 3 hour practical exam on web development with HTML, CSS and JavaScript
Functions break code into reusable named blocks that take parameters and return values; objects group data and behaviour together (spec 9.3.2 h and i).
Functions, parameters and arguments
function area(width, height) { // width and height are parameters
return width * height;
}
function greet(name) { // a function with no return value
console.log("Hello " + name);
}
let a = area(4, 5); // 4 and 5 are arguments
console.log(a);
greet("Sam");
console.log(area(2, 3) + area(1, 1));Output:
20
Hello Sam
7- A parameter is the variable named in the function definition; an argument is the actual value passed in when the function is called. Pearson's 2025 report noted candidates mixing these up.
- return sends a value back to where the function was called and ends the function. A function with no return gives undefined.
- Functions avoid repeated code, can be tested on their own, and make programs easier to read and maintain (decomposition).
Scope and function expressions
let count = 0; // global: visible everywhere
function addOne() {
let step = 1; // local: only inside the function
count = count + step;
}
addOne();
addOne();
console.log(count);
const double = function (n) { return n * 2; };
const triple = n => n * 3; // arrow function
console.log(double(5), triple(5));Output:
2
10 15A variable declared with let or const inside a function (or any block in curly brackets) is local to it. Use local variables where possible, so functions do not interfere with each other. Functions can be stored in variables and passed to other functions, as event handlers are.
Objects and classes (object orientation)
const member = {
name: "Ravi",
visits: 3,
addVisit: function () { this.visits++; }
};
member.addVisit();
console.log(member.name + " " + member.visits);
class Booking {
constructor(name, people) {
this.name = name;
this.people = people;
}
cost(pricePerPerson) {
return this.people * pricePerPerson;
}
}
const b1 = new Booking("Lee", 4);
console.log(b1.name + " pays " + b1.cost(7.5));Output:
Ravi 4
Lee pays 30An object has properties (data, such as name) and methods (functions, such as addVisit). this refers to the object the method belongs to. A class is a template; new creates an instance (an object) and runs the constructor. The DOM itself is made of objects: document is an object, and every element is an object with properties (textContent, style) and methods (addEventListener).
Worked example
Write a function calcTotal that takes a price and a quantity and returns the total with 20% VAT added. Call it for a price of 5 and a quantity of 3.
- Two parameters: price and quantity.
- Return price * quantity * 1.2.
- Call it with the arguments 5 and 3: 18
Answer: ```js function calcTotal(price, quantity) { return price * quantity * 1.2; } console.log(calcTotal(5, 3)); ```
Check yourself
- What is displayed when this code runs?
```js
function f(x) {
return x * x + 1;
}
console.log(f(3) + f(2));
```
Show answer
15. f(3) = 10 and f(2) = 5, so 15.
- In `function tax(amount, rate) { return amount * rate; }` and the call `tax(200, 0.2)`, what are 200 and 0.2?
- Parameters
- Arguments
- Return values
- Properties
Show answer
Arguments. Values passed in a call are arguments; amount and rate in the definition are parameters.
- What is displayed when this code runs?
```js
function add(a, b) {
let s = a + b;
}
console.log(add(2, 3));
```
- 5
- s
- 23
- undefined
Show answer
undefined. add has no return statement, so it gives undefined.
- What is displayed when this code runs?
```js
let total = 10;
function change() {
let total = 99;
total = total + 1;
}
change();
console.log(total);
```
Show answer
10. The let inside change() makes a separate local variable; the global total is unchanged: 10.
- What is displayed when this code runs?
```js
const counter = {
value: 5,
inc: function (n) { this.value += n; }
};
counter.inc(3);
counter.inc(2);
console.log(counter.value);
```
Show answer
10. 5 + 3 + 2 = 10; this refers to counter.
- What is displayed when this code runs?
```js
class Rect {
constructor(w, h) {
this.w = w;
this.h = h;
}
perimeter() {
return 2 * (this.w + this.h);
}
}
const r = new Rect(3, 4);
console.log(r.perimeter());
```
Show answer
14. 2 x (3 + 4) = 14.
- Give one benefit of writing code as functions rather than one long block.
Show answer
The function can be reused by calling it several times, so the code is not repeated.. Functions avoid repetition (write once, call many times), are easier to test and debug, and make the program easier to read and maintain.
Sources
- Pearson Edexcel International Advanced Subsidiary/Advanced Level in Information Technology specification (first teaching 2018), Unit 2 Topics 7 to 11
- Pearson qualifications: Edexcel International Advanced Level Information Technology (2018)
- Pearson WIT12/01 examiner report, June 2025 series
Last updated 8 November 2026. Spotted a mistake? Tell us.