Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript Arrays

Total questions: 30

Worksheet time: 18mins

Name
Class
Date
1.

What is proper syntax for declaring a array in JavaScript?

a)

var arrayName =[ ];

b)

var arrayName[ ] ={ };

c)

array arrayName ={ };

d)

obj var arrayName =[ ];

2.

Which definition below best describe an array?

a)

An array is a function identifier that can hold more than one parameter.

b)

An array is a beam of light.

c)

An array is a special variable, which can hold more than one value at a time.

d)

An array is a special function, which can hold more than one value at a time.

3.

What is first index value of an array?

a)

-1

b)

0

c)

1

d)

undefine

4.

The length() method for an array will return _____.

a)

the number of elements in the array

b)

the last index value of the array.

c)

the length of the name of the array variable

d)

the capacity of the array

5.

The push() method append to the _______ of the array.

a)

beginning

b)

middle

c)

end

d)

none of the above

6.

The pop() method removes the _______ element of the array.

a)

beginning

b)

middle

c)

end

d)

none of the above

7.

The push() method adds a new element to the beginning of an array.

a)

true

b)

false

8.

The push() method adds a new element to the end of an array

a)

true

b)

false

9.

The shift() method removes the first array element and "shifts" all other elements to a lower index.

a)

true

b)

false

10.

The unshift() method adds a new element to an array (at the beginning), and "unshifts" older elements.

a)

true

b)

false

11.

The sort() method sorts in JavaScript will arrange an array alphabetically, and arrange numbers in ascending order.

a)

true

b)

false

12.

The sort() method sorts in JavaScript will arrange an array alphabetically, but will not sort numbers in ascending or descending order.

a)

true

b)

false

13.

What will be the output to the console for the following code?

a)

["New York", "Texas", "New Mexico", "Arizona"]

b)

["New York", "Texas", "New Mexico", "Arizona", "Washington"]

c)

["Texas", "New Mexico", "Arizona", "Washington"]

d)

["Arizona", "New Mexico", "New York", "Texas", "Washington"]

14.

What will be the output to the console for the following code:


var colors =["Red", "Green", "Yellow", "Orange", "Blue"];

colors.splice(0,3, "Purple");

console.log(colors);

a)

["Purple", "Green", "Yellow"]

b)

["Purple", "Green", "Yellow", "Orange", "Blue"]

c)

["Red", "Green", "Yellow", "Orange", "Blue"]

d)

["Purple", "Orange", "Blue"]

15.

What will be the output to the console for the following code:


var colors =["Red", "Green", "Yellow", "Orange", "Blue"];

colors.splice(1,0, "Purple");

console.log(colors);

a)

[ "Orange", "Purple", "Green", "Yellow"]

b)

["Green", "Purple", "Yellow", "Orange", "Blue"]

c)

["Red", "Green", "Purple", "Yellow", "Orange", "Blue"]

d)

["Red", "Purple", "Green", "Yellow", "Orange", "Blue"]

16.

What will be the output to the console for the following code:


var colors =["Red","Green","Yellow","Orange","Blue"];

colors.reverse();

console.log(colors);

a)

["Blue", "Green", "Orange", "Red", "Yellow"]

b)

["Blue", "Orange", "Yellow", "Green", "Red"]

c)

["Red", "Green", "Purple", "Yellow", "Orange", "Blue"]

d)

["Red", "Purple", "Green", "Yellow", "Orange", "Blue"]

17.

What will be the output to the console for the following code:


var colors =["Red","Green","Yellow","Orange","Blue","Amber"];

colors.sort();

console.log(colors);

a)

["Red","Green","Yellow","Orange","Blue"]

b)

["Amber", "Blue", "Green", "Orange", "Red", "Yellow"]

c)

["Amber", "Blue", "Green", "Orange", "Red"]

d)

["Red","Green","Yellow","Orange","Blue","Amber"]

18.

What will be the output to the console for the following code:


var colors =["Red","Green","Yellow","Orange"];

colors.shift();

console.log(colors);

a)

["Red","Green","Yellow"]

b)

["Yellow","Orange"]

c)

["Green", "Yellow", "Orange"]

d)

["Red","Green","Yellow","Orange"]

19.

What will be the output to the console for the following code:


var colors =["Red","Green","Yellow","Orange"];

console.log(colors.length);

a)

5

b)

3

c)

4

d)

2

20.

What will be the output to the console for the following code:


var numbers =[100,125,137,16];

numbers.sort()

console.log(numbers);

a)

[100, 125, 137, 16]

b)

[16,100, 125, 137]

c)

[16,100, 137, 8]

d)

[8,16,100, 137]

21.

The sort() method will produce incorrect result when sorting numbers, even if you make the number into a string.

a)

true

b)

false

22.

The forEach() method calls a function once for each array element.

a)

true

b)

false

23.

What will be the output to the console for the following code:


var numbers =["100","125","137","16"];

numbers.sort()

console.log(numbers);

a)

["100", "125", "137", "16"]

b)

["16", "100", "125", "137"]

c)

["16", "100", "137", "8"]

d)

["8", "16", "100", "137"]

24.

What will be the output to the console for the following code:


var numbers =["100","125","137","16"];

numbers.pop()

console.log(numbers);

a)

["100", "137", "16"]

b)

["125","137","16"]

c)

["100","125","137","16"]

d)

["100", "125", "137"]

25.

To display information to the screen and not to the console which command should you use?

a)

console.log()

b)

display.write()

c)

document.write( )

d)

print.screen()

26.
What surrounds a string?
a)

Single or Double Quotations

b)
Curly Brackets
c)
Parenthesis
d)
Square Brackets
27.

What would be the output for the following code block?


var n =["Left Eye","Chilli","T-Boz"];


console.log(typeof n);

a)

string

b)

undefined

c)

array

d)

object

28.

JavaScript was created by Brendan Eich in ____?

a)

1895

b)

1980

c)

2017

d)

1995

29.
What surrounds an array?
a)
Quotations
b)
Curly Brackets
c)
Parenthesis
d)
Square Brackets
30.

Which of the variables below is an array?

a)

var names="array"

b)

var names = array;

c)

var names = [];

d)

var names[];