← Quiz: Functions, Arrays and Objects: all 10 questions
Quiz: Functions, Arrays and Objects · Question 2 of 10
What does this print? (code)
What does this print?
console.log([5, 1, 10].sort());
- A.[ 1, 5, 10 ]
- B.[ 1, 10, 5 ]
- C.[ 10, 5, 1 ]
- D.[ 5, 1, 10 ]
Answer & explanation
Correct answer: [ 1, 10, 5 ]
Without a compare function, sort compares as strings: "1" < "10" < "5".
Can you get the rest right without peeking?
Take the timed Quiz: Functions, Arrays and Objects quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →