Recall & Review
beginner
What is an array in JavaScript?
An array is a list that holds multiple values in order. You can think of it like a row of boxes, each with a number to find what’s inside.
Click to reveal answer
beginner
How do you access the first element of an array named
fruits?Use
fruits[0]. Arrays start counting at 0, so the first box is number 0.Click to reveal answer
beginner
What happens if you try to access an index that is outside the array length?
You get
undefined because there is no value stored at that position.Click to reveal answer
intermediate
How can you find the last element of an array
arr without knowing its length?Use
arr[arr.length - 1]. arr.length gives the number of items, so subtract 1 to get the last index.Click to reveal answer
intermediate
What is the difference between
arr[1] and arr['1'] in JavaScript?There is no difference. JavaScript converts the string '1' to the number 1 when accessing array elements.
Click to reveal answer
What index do arrays in JavaScript start counting from?
✗ Incorrect
Arrays always start at index 0, so the first element is at position 0.
What will
arr[5] return if arr has 3 elements?✗ Incorrect
Accessing an index outside the array length returns undefined, not an error.
How do you get the last element of an array
myArray?✗ Incorrect
The last element is at index length minus 1 because counting starts at 0.
What does
arr['2'] access in JavaScript?✗ Incorrect
JavaScript converts string '2' to number 2 when accessing array elements.
If
colors = ['red', 'green', 'blue'], what is colors[1]?✗ Incorrect
Index 1 is the second element, which is 'green'.
Explain how to access elements in a JavaScript array and what happens if you use an index outside the array.
Think about how you find items in a list by their position.
You got /3 concepts.
Describe how to get the last element of an array without knowing its length beforehand.
Remember the array length counts items, but indexes start at zero.
You got /3 concepts.