Recall & Review
beginner
What does the
length property of an array represent in JavaScript?The
length property shows how many elements are in the array. It tells you the total number of items stored.Click to reveal answer
beginner
If you have <code>let arr = [1, 2, 3, 4];</code>, what is <code>arr.length</code>?The value of
arr.length is 4 because there are 4 elements in the array.Click to reveal answer
intermediate
Can you change the
length property of an array? What happens if you set it to a smaller number?Yes, you can set
length to a smaller number. This will remove elements from the end of the array, shortening it.Click to reveal answer
intermediate
What happens if you set the
length property of an array to a larger number?The array's size increases, but new elements are empty slots (holes). The array has more space but no new values.
Click to reveal answer
intermediate
Is the
length property always equal to the number of elements you see when you print the array?Not always.
length counts all elements including empty slots. Some elements might be undefined or missing but still counted.Click to reveal answer
What does
array.length return?✗ Incorrect
array.length returns how many elements are in the array.
If
arr = [10, 20, 30], what is arr.length?✗ Incorrect
There are 3 elements, so arr.length is 3.
What happens if you set
arr.length = 2 on arr = [1, 2, 3, 4]?✗ Incorrect
Setting length smaller removes elements from the end.
What is the value of
arr.length after arr.length = 5 if arr = [1, 2]?✗ Incorrect
Setting length larger increases size with empty slots, so length is 5.
Does
length count empty slots in an array?✗ Incorrect
length counts all slots, even if empty or undefined.
Explain how the
length property works in JavaScript arrays and what happens when you change it.Think about how length relates to array size and content.
You got /4 concepts.
Describe a real-life example where changing the array length property might be useful.
Imagine a list of tasks you want to trim or expand.
You got /3 concepts.