Algorithms and Data Structures · Junior · Question 36 of 75

What is important to remember about arr.sort()?

Explanation

sort mutates the original array, which can surprise code that still uses it, for example React state. toSorted() (ES2023) returns a sorted copy instead.

Further reading

Problem with a question

Algorithms and Data Structures · Junior · question 36

Test yourself

Take the Algorithms and Data Structures · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz