Question 3
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
console.log([5, 25, 100, 1].sort());
- A [ 1, 5, 25, 100 ]
- B [ 100, 25, 5, 1 ]
- C [ 1, 100, 25, 5 ] Correct
- D [ 5, 25, 100, 1 ]
Correct Answer: Option C
Without a comparator the numbers are compared as strings: "1" < "100" < "25" < "5".
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!