DEV Community

Discussion on: Is JavaScript the most confusing programming language?

Collapse
 
pinotattari profile image
Riccardo Bernardini

IMHO JS is not just confusing, but it is deeply flawed at the design and philosophical level.

Maybe the biggest flaw (that many consider a feature) is the insistence to doing automatic type conversion, even in context where it makes no sense. (BTW, I program in Ada where no automatic type conversion is done and I like it in this way; it saved me from many bugs).

I mean, an expression like 1 + '1' that is, adding a string and a number, makes no sense at all; most probably is not something the developer wanted, but the consequence of an error. Moreover, what are you going to do? Convert the integer in string or the other way around? What about '1'-1 or 'b'+3? In this case the sensible thing to do is to raise an error. There is one thing worst than a program that stops because of an error: a program with an error that continue nevertheless.

Automatic type conversion also gives rise to one of the worst behavior of JS (still IMHO): equality operator == is not transitive (I suspect that the loss of transitivity can cause several algorithm to break). See for example,

stackoverflow.com/questions/544715...

Along the same lines, but with more humor, a classic:

destroyallsoftware.com/talks/wat