146k views
2 votes
What will be displayed in the console when this program runs?

var numList = [10,20,30];
console.log(numList[numlist.length-2]);

User Str
by
4.2k points

2 Answers

5 votes

Answer:

20

Step-by-step explanation:

User ManiAm
by
3.5k points
6 votes

Answer:

20 will be displayed on the console.

Step-by-step explanation:

Given code is:

var numList = [10,20,30];

console.log(numList[numlist.length-2]);

The first line of code declares an array named numList and assigns it values given in the square brackets.

The second line of code is written to display the element on the index obtained by [numlist.length-2]

[numlist.length-2] means the second index.

Hence,

after running the code on JavaScript editor and dry running the code

20 will be displayed on the console.

User Florian Wendelborn
by
3.7k points