Javascript Objects And Arrays Quiz

JavaScript: Objects and Arrays Quiz

Given a number of elements that need to stay in order, would you use an Object or an Array?

Object
Array

Given a collection of artists and lists of their songs, would you store the artist-song-list pairs in an Object or an Array?

Object
Array

True or false: All the elements in an array must be of the same type.

True
False

True or false: All keys in an object are strings.

True
False

What happens to the array in the following code snippet?

const dogs = ["Fido", "Odie", "Oscar"]

dogs.length

dogs.length = 1

Nothing
The array becomes just ["Oscar"]
The array becomes just ["Fido"]
The array becomes just ["Odie", "Oscar"]

What are the keys in the object after running the code below?

const artistsAndSongs = {
  'Prince': ["Purple Rain", "When Doves Cry"],
  'The Beatles': ["Revolution", "Norwegian Wood"],
  'Joni Mitchell': ["A Case of You", "Sunny Sunday"],
  'Justin Bieber': ["Baby"]
}

artistsAndSongs['Daft Punk'] = ["Harder, Better, Faster, Stronger"]

delete artistsAndSongs["Justin Bieber"]

['Prince', 'The Beatles', 'Joni Mitchell', 'Justin Bieber', 'Daft Punk']
['Prince', 'The Beatles', 'Joni Mitchell', 'Justin Bieber']
['Prince', 'The Beatles', 'Joni Mitchell']
['Prince', 'The Beatles', 'Joni Mitchell', 'Daft Punk']

If we run artistsAndSongs['Daft Punk'].push("Around the World") after running the code below, what is the value of the object?

const artistsAndSongs = {
  'Prince': ["Purple Rain", "When Doves Cry"],
  'The Beatles': ["Revolution", "Norwegian Wood"],
  'Joni Mitchell': ["A Case of You", "Sunny Sunday"],
  'Justin Bieber': ["Baby"]
}

artistsAndSongs['Daft Punk'] = ["Harder, Better, Faster, Stronger"]

delete artistsAndSongs["Justin Bieber"]

const artistsAndSongs = {
  'Prince': ["Purple Rain", "When Doves Cry"],
  'The Beatles': ["Revolution", "Norwegian Wood"],
  'Joni Mitchell': ["A Case of You", "Sunny Sunday"],
  'Daft Punk': ["Harder, Better, Faster, Stronger"]
}

const artistsAndSongs = {
  'Prince': ["Purple Rain", "When Doves Cry"],
  'The Beatles': ["Revolution", "Norwegian Wood"],
  'Joni Mitchell': ["A Case of You", "Sunny Sunday"],
  'Daft Punk': ["Harder, Better, Faster, Stronger", "Around the World"]
}

const artistsAndSongs = {
  'Prince': ["Purple Rain", "When Doves Cry"],
  'The Beatles': ["Revolution", "Norwegian Wood"],
  'Joni Mitchell': ["A Case of You", "Sunny Sunday"],
  'Daft Punk': ["Around the World"]
}

const artistsAndSongs = {
  'Prince': ["Purple Rain", "When Doves Cry"],
  'The Beatles': ["Revolution", "Norwegian Wood"],
  'Joni Mitchell': ["A Case of You", "Sunny Sunday"]
}

What is the result of the following code in a browser that supports the spread operator?

const oneTwoThree = [1, 2, 3]
const sevenEightNine = [7, 8, 9]

[4, 5, 6, ...oneTwoThree, ...sevenEightNine]

[4, 5, 6, 7, 8, 9, 1, 2, 3]
[4, 5, 6, 1, 2, 3, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8, 9]
Error

Given the array const letters = ["alpha", "gamma", "delta"], which operation(s) return the array ["alpha", "beta", "gamma", "delta"]?

letters.push("beta")
letters.unshift('beta')
[...letters.slice(0, 1), 'beta', ...letters.slice(1)]
letters.splice(1, 1, 'beta')
letters.splice(1, 0, 'beta')

View Javascript Objects And Arrays Quiz on Learn.co and start learning to code for free.

Unlock your future in tech
Learn to code.

Learn about Flatiron School's Mission

With a new take on education that falls somewhere between self-taught prodigy and four-year computer science degree, the Flatiron School promises to turn students with little programming experience into developers.

In the six months since the Manhattan coding school was acquired by WeWork, it has spawned locations in Washington, D.C., Brooklyn, and London. Now, WeWork is opening a fourth Flatiron School location, this time in Houston.

Adam Enbar, Flatiron School's cofounder, believes now is the time to grow. "How the world is changing has impacted working and learning in very similar ways. We think education fundamentally is about one thing: enabling people to pursue a better life."

Learn. Love. Code.
Students come to Flatiron School to change their lives. Join our driven community of career-changers and master the skills you need to become a software engineer or a data scientist.
Find Us