Answer:
The scores array: 70,20,35,15,40
Step-by-step explanation:
I will explain the code line by line:
var scores = [70, 20, 35, 15];
The above statement declares and assigns values to an array named scores
scores[scores.length] = 40;
The above statement uses length to set the length of the scores array. It sets the last element of the scores array to 40. So this means 40 is set as the last element of scores.
scores.length returns the length of the scores array i.e. 4 as there are 4 elements in scores array 70,20,35,15
So the statement becomes:
scores[4] = 40;
This assigns value 40 to the 4th index of the scores array. Do not confuse 4th index with 4th element of the array because array element location starts from 0. So scores[4] does not mean 4th element but scores[4] means 4th index position of scores array. This makes 5th element of scores. So set the element 40 as 5th element at 4th index of scores.
alert("The scores array: " + scores);
This displays an alert box with the following message:
The scores array: 70,20,35,15,40