MCQ Practice Single Best Answer Topic: Javascript Functions MCQ

Q What does the sort() function do in JavaScript?

Question ID
#4869
Subchapter
Javascript Functions MCQ
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A Sorts the elements of an array in ascending order
  • B Sorts the elements of an array in descending order
  • C Sorts the elements of an array in random order
  • D None of these
Correct Answer: A

Explanation

The sort() function sorts the elements of an array in ascending order.
By default, it compares the elements as strings.
You can pass a comparison function as an argument to sort the elements in a different way.

Share This Question

Share this MCQ with your friends or study group.