Question:medium

What will be the output of the following JavaScript code ?
<html> <body> <script> document.write([21, 121, 120, 24, 202].sort()); </script> </body> </html>

Show Hint

To sort numbers in normal ascending numeric order, always pass a comparison function to sort(): myArray.sort((a, b) => a - b); This subtraction-based callback handles numbers correctly instead of using string comparison.
Updated On: Jun 29, 2026
  • 21,121,120,24,202
  • 21,24,120,121,202
  • 120,121,202,21,24
  • 21,121,120,202,24
Show Solution

The Correct Option is C

Solution and Explanation

Was this answer helpful?
0