wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Chapter 5 : JavaScript Objects & Arrays

Total questions: 20

Worksheet time: 13mins

Name
Class
Date
1.

How many values or properties can an Object contain

a)

One value/properties

b)

Two values/properties

c)

Multiple values/properties

2.

Identify the name of the object in the following code:


var car = { model: "EXPLORER", brand: "Ford", IntroductionYear: 2019 }

a)

car

b)

"EXPLORER"

c)

model

d)

var

3.

Identify a key in the following code:


var car = { model: "EXPLORER", brand: "Ford", IntroductionYear: 2019 }

a)

car

b)

"EXPLORER"

c)

model

d)

var

4.

Identify a value in the following code:


var car = { model: "EXPLORER", brand: "Ford", IntroductionYear: 2019 }

a)

car

b)

"EXPLORER"

c)

model

d)

var

5.

How would you access the value "Ford"


var car = { model: "EXPLORER", brand: "Ford", IntroductionYear: 2019 }

a)

car.Ford;

b)

car["brand"];

c)

car.getbrand;

d)

car.brand;

6.

What is DRIVE in the code below?


var car = {

DRIVE: function()

alert("Drive");

}

a)

A property

b)

A method

c)

A variable

d)

A function

7.

What is the code that allows you to make use DRIVE?


var car = {

DRIVE: function()

alert("Drive");

}

a)

drive()

b)

DRIVE()

c)

car.drive()

d)

car.DRIVE()

8.

What does the following code do?


var car = { model: "EXPLORER", brand: "Ford", IntroductionYear: 2019 }

var text = "";

for (var x in car) {

text += car[x] + " ";

}

a)

Displays all the code in the object

b)

Displays all the values in the object

c)

Displays all the names of the keys in the object

9.

Which of these creates an array in Javascript named myNumber that contains the following numbers:


5, 7, 11, 23, 1


Use the var keyword to create variables

(a)  

10.

Which will retrieve the "Singapore" from the following array?


var countries = ["Thailand", "Myanmar", "Malaysia", "Singapore", "Indonesia"]

a)

countries[3]

b)

countries[2]

c)

countries[0]

d)

countries[1]

e)

countries[4]

11.

Given the following array


var numbers = [752, 363, 587, 423, 688, 999]


What is the index of the number 999

(a)  

12.

Which of these lines of code will give you the number of elements in the numbers array?

a)

numbers.value

b)

numbers.innerHTML

c)

numbers.length

13.

Fill in the Blanks to allow the code to display an alert message for all the cars in the array


var cars = [“Saab”, “Volvo”, “BMW”];


for (var x = 0; x < cars.length; x++)

alert(cars[_______]);

a)

cars

b)

x

c)

y

d)

length

14.

Given the following object:


var person = {

fn: “Raymond”,

ln: “Chia”,

age: 25 };


Which code will retrieve the value "Chia"

a)

person[1]

b)

person["ln"]

c)

person.age

d)

person.fn

15.

Given the following array:


var person = ["Raymond", "Chia", "25"]


Which code will retrieve the value "Chia"?

a)

person[1]

b)

person["ln"]

c)

person.age

d)

person.fn

16.

You retrieve values from objects by passing in the (a)   of the value into the [ ]

17.

You retrieve values from arrays by passing in the (a)   of the value into the [ ]

18.

Which of the following will remove the last element from an array and return the value?

a)

push()

b)

pop()

c)

shift()

19.

Which of these ways of creating a new Array is valid?

a)

var x = ["A", "B", "C"];

b)

var x = new Array["A", "B", "C"];

c)

var x = (A", "B", "C");

d)

var x = new Array("A", "B", "C");

20.

Which of the following will add a new element to the end of the array?

a)

push()

b)

pop()

c)

shift()