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
πŸ’¬ Discuss
βœ… Correct Answer: (B) [1, 2, 3, 4]
Explanation: Arrays are reference types, so modifying y also affects x.
Explanation by: Chandani
Arrays are reference types, so modifying y also affects x.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
101
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Chandani
Publisher
πŸ“ˆ
95%
Success Rate