Question 4
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const a = [3, 1, 2];
const b = a.sort();
b.push(4);
console.log(a === b, a);
- A true [ 1, 2, 3, 4 ] Correct
- B false [ 3, 1, 2 ]
- C false [ 1, 2, 3 ]
- D true [ 1, 2, 3 ]
Correct Answer: Option A
sort works in place and returns the same array object, so b is just another name for a.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!