const arr = [10, 20, 30, 40]; arr[2] = 99; console.log(arr.join(' -> ') + ' -> null');
The array starts as [10, 20, 30, 40]. Updating arr[2] changes the third element from 30 to 99. The printed output shows the updated array elements separated by ' -> ' and ends with ' -> null'.
const arr = [1, 2, 3]; arr[5] = 10; console.log(arr.length); console.log(arr.join(' -> ') + ' -> null');
Assigning arr[5] = 10 sets the sixth element (index 5) to 10. The array length becomes 6. The missing elements (index 3 and 4) are empty slots (holes), which when joined are treated as empty strings, not 'undefined'. Printing the array shows empty positions for those indices.
const arr = [5, 10, 15]; arr[1] == 20; console.log(arr.join(' -> ') + ' -> null');
The code uses '==' which is a comparison operator, not assignment. So arr[1] is not changed. The output remains the original array.
const arr = [{val: 1}, {val: 2}, {val: 3}];
arr[1].val = 99;
console.log(arr.map(x => x.val).join(' -> ') + ' -> null');Updating arr[1].val changes the 'val' property of the second object in the array. The output reflects this updated value.
const arr = [0, 0, 0, 0, 0]; arr[1] = arr[3] = 5; arr[2] = arr[1] + arr[3]; arr[4] = arr[2] * 2; console.log(arr.join(' -> ') + ' -> null');
arr[1] and arr[3] are both set to 5. Then arr[2] = 5 + 5 = 10. Finally, arr[4] = 10 * 2 = 20. The first element remains 0.
