Creating an object with new

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Creating an object with new

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line correctly creates a Dog object from the Dog class?
A const rex = Dog('Rex', 3);
B const rex = new Dog('Rex', 3);
2. True or false: new Dog('Rex', 3) passes 'Rex' and 3 to the constructor.
A False
B True
3. Which line stores the new object so you can use it later?
A const rex = new Dog('Rex', 3);
B new Dog('Rex', 3);
4. What happens when you run const max = Dog('Max', 5); and Dog is a class?
A An error, because new is missing
B A Dog object is created anyway
5. Given class Cat { constructor(name, age) {...} }, which call is correct?
A const cat1 = new Cat('Mia', 2);
B const cat1 = new cat('Mia', 2);

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1const rex = new Dog('Rex', 3); AMakes a new Track object using the Track class and saves it in song
2const song = new Track('Wave', 210); BThe keyword new is missing. Calling a class without new causes an error, so no object is created.
3Put the keyword new before the class name to create an object from a class CThe new object is not stored in a variable, so the program has no way to use it again later.
4The arguments in the brackets are passed to the constructor, in the same order as its parameters DCreates a Dog object, sends 'Rex' and 3 to the constructor, and stores the object in the variable rex
5const rex = Dog('Rex', 3); Econst pet = new Dog('Bella', 5);
6new Dog('Rex', 3); Fconst rex = new Dog('Rex', 3);

Definitions

new ClassName(arguments)

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
const rex = ___ Dog('Rex', 3);
2.
const rex = new ___('Rex', 3);
3.
const ___ = new Dog('Rex', 3); console.log(rex.name);
4.
_____ rex = new Dog('Rex', 3);
5.
let bo = new Dog('Bo', 5); console.log(__.name);

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A const nums = [1, 2, 2, 3];
B console.log(nums.length);
C const unique = Set(nums);
D console.log(unique.size);
Question 2
A const pairs = [['a', 1]];
B const m = new map(pairs);
C console.log(m.get('a'));
Question 3
A class Dog() {
B constructor(n) {this.n = n}
C }
D const rex = new Dog('Rex');
Question 4
A const d = Date new(2025, 5);
B console.log(d.getMonth());
C console.log(d.getFullYear());
Question 5
A class Dog {
B constructor(n) {this.n = n}
C }
D const rex = Dog('Rex');
E console.log(rex.n);

Answer Key

Creating an object with new
Section A: Quick Questions
Q1
B — const rex = new Dog('Rex', 3);
Q2
B — True
Q3
A — const rex = new Dog('Rex', 3);
Q4
A — An error, because new is missing
Q5
A — const cat1 = new Cat('Mia', 2);
Section B: Match the Pairs
Q1
const rex = new Dog('Rex', 3); → Creates a Dog object, sends 'Rex' and 3 to the constructor, and stores the object in the variable rex
Q2
const song = new Track('Wave', 210); → Makes a new Track object using the Track class and saves it in song
Q3
Put the keyword new before the class name to create an object from a class → const pet = new Dog('Bella', 5);
Q4
The arguments in the brackets are passed to the constructor, in the same order as its parameters → const rex = new Dog('Rex', 3);
Q5
const rex = Dog('Rex', 3); → The keyword new is missing. Calling a class without new causes an error, so no object is created.
Q6
new Dog('Rex', 3); → The new object is not stored in a variable, so the program has no way to use it again later.
Section C: Definitions
Q1
new ClassName(arguments) — Creates an object from a class and passes the arguments to the constructor. Store it in a variable, e.g. const rex = new Dog('Rex', 3). Leaving out new causes an error.
Section D: Fill in the Blanks
Q1
const rex = new Dog('Rex', 3);
Q2
const rex = new Dog('Rex', 3);
Q3
const rex = new Dog('Rex', 3); console.log(rex.name);
Q4
const rex = new Dog('Rex', 3);
Q5
let bo = new Dog('Bo', 5); console.log(bo.name);
Section E: Spot the Error
Q1
C — The new keyword is missing. Set is a class, so calling it without new causes a TypeError. It should be const unique = new Set(nums);
Q2
B — Class names are case-sensitive. map (lowercase) does not exist, so JavaScript gives a ReferenceError. It should be new Map(pairs).
Q3
A — A class header has no round brackets. The class never gets defined, so new Dog('Rex') can't work. It should be class Dog {
Q4
A — The new keyword must come directly before the class name. The correct line is const d = new Date(2025, 5);
Q5
D — Without new, the Dog constructor is not run and JavaScript throws a TypeError. It should be const rex = new Dog('Rex');