What does the following JavaScript code snippet do? [code] data.sort(function(a,b),b-a); [/code]

Giao Linh

New member
What does the following JavaScript code snippet do?
Code:
data.sort(function(a,b),b-a);
A. Sort in the alphabetical order
B. Sort in the chronological order
C. Sort in reverse alphabetical order
D. Sort in reverse numerical order
 
Answer: d
Explanation: ’a-b’ is used to sort the array in ascending order whereas ‘b-a’ is used to sort the array in descending order. Therefore the above code snippet sorts an array in reverse numerical order.
 

Tìm kiếm

Back
Top