Now every language that handles numeric values as IEEE754 floating point numbers has the exact same issue. The first one can be fixed by using BigInt:
9999999999999999n==10000000000000000n// → false
The other examples cannot be easily fixed, but will fail in most other languages either.
typeofNaN=='number'→trueNaN!=NaN→true
You have detected an interesting feature of the language to support mathematical functions. NaN is basically an undefined numeric value, thus compares equal to nothing, not even itself. You can detect it by using isNaN. In other language, you'd probably express this with undefined or null, but that would still compare equal to similar undefined solutions, which could lead to mistakes.
[8,19,24,1,5].sort()→[1,19,24,5,8]
Having a look at the documentation shows us that Array.prototype.sort will compare the string values of the items for sorting, but you can easily use a lambda function to compare two items:
[8,19,24,1,5].sort((x,y)=>x-y)→[1,5,8,19,24]
So actually most of your issues either are not actual issues of the language or can be easily solved by learning more about the language instead of expecting it to work exactly like the languages that you already know.
The only valid point you have is that the weak type system can easily lead to errors - and that is already rectified by TypeScript and similar static type checkers.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Let's have a look at the examples that make you hate JavaScript, shall we?
Now every language that handles numeric values as IEEE754 floating point numbers has the exact same issue. The first one can be fixed by using BigInt:
The other examples cannot be easily fixed, but will fail in most other languages either.
You have detected an interesting feature of the language to support mathematical functions. NaN is basically an undefined numeric value, thus compares equal to nothing, not even itself. You can detect it by using isNaN. In other language, you'd probably express this with undefined or null, but that would still compare equal to similar undefined solutions, which could lead to mistakes.
Having a look at the documentation shows us that
Array.prototype.sort
will compare the string values of the items for sorting, but you can easily use a lambda function to compare two items:So actually most of your issues either are not actual issues of the language or can be easily solved by learning more about the language instead of expecting it to work exactly like the languages that you already know.
The only valid point you have is that the weak type system can easily lead to errors - and that is already rectified by TypeScript and similar static type checkers.