wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript Data Structures

Total questions: 19

Worksheet time: 10mins

Name
Class
Date
1.

If you want to be able to look up a value by an index value (4, for example) , which data structure should you choose?

a)

array

b)

object

c)

set

d)

grid

2.

What is an Object?

a)

An ordered list of objects

b)

An unordered list of objects

c)

A collection of (key, value) pairs

d)

elements listed in a grid form

3.

We want to make a grocery list in our program. Which of the following is the correct way to make an array/list?

a)

var groceries = ["milk" "sugar" "eggs" "cake"];

b)

var groceries = ["milk, sugar, eggs, cake"];

c)

var groceries = "milk, sugar, eggs, cake";

d)

var groceries = ["milk", "sugar", "eggs", "cake"];

4.

What method can we use to find the index of a particular element in an array?

a)

.index

b)

indexOf

c)

inIt

d)

findElement

5.

The index of the very first item in an array is 1.

a)

true

b)

false

6.

var numbers = [0, 1, 2, 3, 4];

How can we add a 6 to the end of numbers?

a)

pop(6)

b)

push(6)

c)

add(5,6)

d)

pop( )

7.

What is a set?

a)

a collection of unique objects that are not in a specific order.

b)

a collection of ordered items.

c)

a collection of (key, value) pairs

d)

Elements in a row and column table

8.

Which of the options below is a set?

a)

["hello", "goodbye"]

b)

{"hello", "goodbye"}

c)

{"hello", "hello", "goodbye"}

d)

{

Jeremy: "123-4567",

Zach: "333-3333"

}

9.

What is a Grid?

a)

A collection of unique items with no particular order

b)

A collection of (key, value) pairs

c)

A collection of items each stored at a specific (row, column) location

d)

An unordered list with unique values

10.

What is an array ?

a)

An unordered collection of items

b)

An ordered collection of items

c)

A collection of (key, value) pairs

d)

A collection of unique objects that are not in a specific order

11.

If you care about the order of data, data should be stored in an object.

a)

false

b)

true

12.

If you want to be able to look up a value by KEY

, what data structure should you use?

a)

object

b)

array

c)

grid

d)

set

13.

What is the output of the following program?

 

function start(){

 

   var arr = [1, 2, 3, 4, 5, 6, 7];

 

   var elem = arr.remove(2);

 

   println(arr);

 

}

a)

[1, 2, 3, 4, 5]

b)

[3, 4, 5, 6, 7]

c)

[1, 2, 4, 5, 6, 7]

d)

[1, 3, 4, 5, 6, 7]

14.

var numbers = [ 1, 2, 3, 4, 5, 6];

How can we remove the last item from the end of this array and store it in a variable called highestNum?

a)

var highestNum = numbers.pop();

b)

var numbers =

highestNum.push(6);

c)

var highestNum = numbers[5];

d)

var numbers = numbers.pop();

15.

numCols() can tell you the number of rows in a grid.

a)

false

b)

true

16.

How can we set the number for Jenny in phonebook to be "867-5309"?

a)

phonebook["Jenny"] =

"867-5309";

b)

phonebook["867-5309", "Jenny"];

c)

phonebook.putJenny

("867-5309");

d)

phonebook ["867-5309"] = "Jenny";

17.

var shoppingList = ["milk", "eggs", "sugar", "bread", "cake"];

Which line of code will correctly change "cake" to "apples"?

a)

shoppingList["apples"] = "cake";

b)

shoppingList[5] = "apples";

c)

shoppingList["cake"] = "apples";

d)

shoppingList[4] = "apples";

18.

What kinds of items can we store in arrays?

a)

anything you can store in a variable

b)

numbers only

c)

numbers or strings of text only

d)

strings of text only

19.

How can we get the number for our friend Jenny out of our object phonebook and store it as a variable named number?

choose all that apply

a)

var jenny = phonebook["Jenny"];

b)

var number = phonebook["Jenny"];

c)

var number = phonebook.Jenny;

d)

var number= phonebook(Jenny);