Question 2
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const queue = ["b", "c"];
const len = queue.unshift("a");
const first = queue.shift();
console.log(len, first, queue);
- A 3 b [ 'a', 'c' ]
- B 3 a [ 'b', 'c' ] Correct
- C [ 'a', 'b', 'c' ] a [ 'b', 'c' ]
- D 2 a [ 'b', 'c' ]
Correct Answer: Option B
unshift returns the new length 3; shift removes and returns the first element "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!