What is the output of the following? “`js const arr = [1, 2, 3]; arr[10] = 99; console.log(arr.length); console.log(arr[5]); “`

JavaScript Professional Medium

JavaScript Professional — Medium

What is the output of the following? “`js const arr = [1, 2, 3]; arr[10] = 99; console.log(arr.length); console.log(arr[5]); “`

Key points

  • JavaScript arrays can have non-contiguous indexes
  • Assigning a value to an index beyond the current length increases the length of the array
  • Accessing an index that was never assigned a value returns undefined

Ready to go further?

Related questions