Comment

Comment by stank345

I hear what you're saying, but it still seems pretty bonkers to me that if you try to sort an array of numbers it will cast them to strings and sort alphabetically (!):

  > [1, 2, 10, 3].sort()
  [ 1, 10, 2, 3 ]
> And yes, I agree that throwing an error here for no argument would be better here (a linter WILL enforce this), but this is hardly a critical shortcoming of JS's standard library

I suppose "critical" is debatable but this seems very fundamental and very unexpected to me.

> you DEFINITELY do not need a utility library just to use the language (especially for your examples)

I hadn't actually considered using a linter to avoid these types of standard library footguns... that's actually a pretty great idea!

parent stank345 4 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton