🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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());
  1. A.[ 1, 5, 10 ]
  2. B.[ 1, 10, 5 ]
  3. C.[ 10, 5, 1 ]
  4. 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 →