CJCoding With Joseph
15free / daySign inCreate account
Back to Code Walkthrough

Array Aliasing vs a Copy

JavaScript code walkthrough · Question 45
mediumArrays

Code

Read carefully. What does this print?
1let a = [1, 2, 3];
2let b = a;
3b.push(4);
4console.log(a.length);
5console.log(a[3]);
6let c = a.slice();
7c.push(5);
8console.log(a.length);

Your answer