r/programminghorror
•
u/Leonnee
•
Jun 12 '25
•
1
Javascript Javascript is filled with horror
2.4k
Upvotes
View all comments
Show parent comment
31
u/Drasern Jun 12 '25
Javascript is built on the foundational concept of continuing execution whenever possible. Things do not throw exceptions unless it is absolutely necessary, you just assume some default functionality and keep going. In this case, there is no way to know what kind of objects are in the array, so it makes more sense to coerce everything to a string than coerce everything to a number. After all, someone might try to sort [1, 2, "a", "17", {prop: "value"}]