Daily JavaScript Quiz - 2024-04-17

  • Home /
  • Daily JavaScript Quiz - 2024-04-17

Daily Quiz - 2024-04-17

let array = [1, 2, 3];
array[6] = 9;
console.log(array[5]);

1

2

3

undefined

The answer is Option 4

  1. The array array is initialized with elements [1, 2, 3].

  2. array[6] = 9; assigns the value 9 to the element at index 6. Since this index is beyond the current length of the array, JavaScript increases the size of the array to accommodate this new index.

  3. The array now looks like this: [1, 2, 3, undefined, undefined, undefined, 9].

  4. console.log(array[5]); tries to access the element at index 5. However, no value has been explicitly assigned to this index, so it returns undefined.

Javascript Quizzes