---
title: "Comment by Usman maaji zaharadeen on \"JavaScript Array Sort Method and its gotchas - Explained with Examples\" | Hashnode"
description: "very interesting blog thanks for this. in ur array to object sort() comparism why using alot of return statement instead of one, one works just fyn for me, is t"
url: "https://hashnode.com/posts/javascript-array-sort-method-and-its-gotchas-explained-with-examples/60558c965f8d512169726440/comment/60570b295f8d512169727918"
---

[Discussion](https://hashnode.com/posts/javascript-array-sort-method-and-its-gotchas-explained-with-examples/60558c965f8d512169726440)

Comment [JavaScript Array Sort Method and its gotchas - Explained with Examples](https://hashnode.com/posts/javascript-array-sort-method-and-its-gotchas-explained-with-examples/60558c965f8d512169726440)

[Usman maaji zaharadeen](https://hashnode.com/@Maaji)

[Mar 21, 2021](https://hashnode.com/posts/javascript-array-sort-method-and-its-gotchas-explained-with-examples/60558c965f8d512169726440/comment/60570b295f8d512169727918)

very interesting blog thanks for this. in ur array to object sort() comparism why using alot of return statement instead of one, one works just fyn for me, is there anything special about returning zero(0)

> const names\_of\_employees = \[ {name:'ahmad', age:30},{name: 'maaji', age: 21}, {name:'musa', age:16}, {name:'bulldozer', age:70} \]
> 
> let sort\_names = names\_of\_employees.slice().sort(function (user1, user2){ if(user1.age < user2.age) return -1; return 0; _why returning this_ })

[Yogesh Chavan](https://hashnode.com/@myogeshchavan97)

[Mar 21, 2021](https://hashnode.com/posts/javascript-array-sort-method-and-its-gotchas-explained-with-examples/60558c965f8d512169726440/comment/60570b295f8d512169727918#reply-60570c5d63a05a21443f2dbf)

Thanks [deeni buba](https://hashnode.com/@Buba). If the age of two objects are equal then both the If conditions will be false and therefore the last `return 0` statement is added.

[Usman maaji zaharadeen](https://hashnode.com/@Maaji)

[Mar 21, 2021](https://hashnode.com/posts/javascript-array-sort-method-and-its-gotchas-explained-with-examples/60558c965f8d512169726440/comment/60570b295f8d512169727918#reply-60578ef863a05a21443f3490)

[Yogesh Chavan](https://hashnode.com/@myogeshchavan97) my mistake I didn't realize the logic, if both failed something is there to return. I understand thanks alot 🙌 for this
