Friday, January 05, 2024

JavaScript sort :(

Scott Robinson on X: "I often forget that, by default, JavaScript sorts integers as if they were strings. 1) This makes no sense 2) I can't imagine how many bugs are sprinkled throughout all the JS code I've written in the last 8 years https://t.co/6yv2ITXRa9" / X

this is hard to believe.... but true :(

array sort in JavaScript is handling numeric values as STRINGS!

[2,13,54].sort() 
> [13, 2, 54]


Scott Robinson (@ScottWRobinson) / X

No comments:

Post a Comment