Multiple choice technology web technology

What is the output for the below lines of code? var myArray = new Array(); myArray[10] = "This is the only element in this array"; alert(myArray.length);

  1. 1

  2. 11

  3. undefined

  4. null

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

JavaScript arrays are dynamic and their length is determined by the highest index plus one. When you assign a value to index 10, the array automatically expands to have a length of 11 (indices 0-10), even though only one element has an actual value.