A

Admin • 833K Points
Coach

Q. What will the output be?

Code:
let x = [1, 2, 3];
let y = x;
y.push(4);
console.log(x);
  • (A) [1, 2, 3]
  • (B) [1, 2, 3, 4]
  • (C) [4]
  • (D) undefined
  • Correct Answer - Option(B)
  • Views: 25
  • Filed under category JavaScript
  • Hashtags:

Explanation by: Admin

Arrays are reference types, so modifying y also affects x.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.