wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Understanding Arrays and Loops in JavaScript

Total questions: 7

Worksheet time: 7mins

Name
Class
Date
1.

What is the index of the first element in an array in most programming languages?

a)

1

b)

0

c)

-1

d)

2

2.

In JavaScript, which method is used to add an element to the end of an array?

a)

add()

b)

append()

c)

push()

d)

insert()

3.

Consider the following JavaScript code: `var numbers = [1, 2, 3, 4]; console.log(numbers[4]);`. What will be the output?

a)

4

b)

3

c)

undefined

d)

Error

4.

Which of the following statements correctly initializes an empty array in JavaScript?

a)

`var myArray = {};`

b)

`var myArray = [];`

c)

`var myArray = new Object();`

d)

`var myArray = new Array();`

5.

What will be the result of the following JavaScript expression: `'5' == 5`?

a)

true

b)

false

c)

undefined

d)

Error

6.

Given the array `var fruits = ['apple', 'banana', 'cherry'];`, write a JavaScript `for` loop to print each fruit in the array.

a)

`for (var i = 0; i < fruits.length; i++) { console.log(fruits[i]); }`

b)

`for (var i = 1; i <= fruits.length; i++) { console.log(fruits[i]); }`

c)

`for (var i = 0; i <= fruits.length; i++) { console.log(fruits[i]); }`

d)

`for (var i = 1; i < fruits.length; i++) { console.log(fruits[i]); }`

7.

Which of the following operators is used to check strict equality in JavaScript?

a)

==

b)

===

c)

!=

d)

!==