Recall & Review
beginner
What is the simplest way to create an empty array in JavaScript?
You can create an empty array using square brackets:
[]. This makes a new list that can hold items.Click to reveal answer
beginner
How do you create an array with initial values 1, 2, and 3?
Use square brackets with the values inside separated by commas:
[1, 2, 3]. This creates an array holding those numbers.Click to reveal answer
intermediate
What does
new Array(5) do in JavaScript?It creates an array with 5 empty slots. The array has length 5 but no actual values set yet.
Click to reveal answer
intermediate
How can you create an array from a string like 'hello'?
Use
Array.from('hello'). This makes an array of each character: ['h', 'e', 'l', 'l', 'o'].Click to reveal answer
intermediate
What is the difference between
[] and new Array()?[] creates an empty array. new Array() also creates an empty array but can behave differently if you pass a number (it sets length).Click to reveal answer
Which syntax creates an array with three elements: 10, 20, and 30?
✗ Incorrect
All these syntaxes create an array with elements 10, 20, and 30.
What does
new Array(4) create?✗ Incorrect
new Array(4) creates an array with length 4 but the slots are empty, not set to undefined.How to create an array from the string 'abc'?
✗ Incorrect
Array.from('abc') creates ['a', 'b', 'c'].Which is the correct way to create an empty array?
✗ Incorrect
Both
[] and new Array() create empty arrays.What happens if you do
new Array(3, 4)?✗ Incorrect
new Array(3, 4) creates an array with two elements: 3 and 4.Explain how to create arrays in JavaScript and the difference between using [] and new Array().
Think about how length and elements are set.
You got /3 concepts.
Describe how to convert a string into an array of characters in JavaScript.
Consider how strings and arrays relate.
You got /3 concepts.