95.7k views
1 vote
Imagine you have this code:

var a = [1, 2, 3];
a) Will this result in a crash?

a[10] = 99;
b) What will this output?

(a[6]);

User Tomik
by
7.9k points

1 Answer

5 votes

Final answer:

The given code will not crash. The value 99 will be added at index 10 of the array 'a'. However, since 'a' only has 3 elements, a[6] will output 'undefined'.

Step-by-step explanation:

The given code: var a = [1, 2, 3]; a[10] = 99;

  1. Will not result in a crash.
  2. It will add the value 99 at index 10 of the array 'a'. However, since the array 'a' only has 3 elements, the indices 0-9 remain undefined.
  3. Therefore, a[6] will output 'undefined'.

User Jamie McAllister
by
8.1k points