top | item 41660281

(no title)

electrosphere | 1 year ago

I believe it's because in JavaScript some values or expressions are "truthy" or "falsey" depending on how they are evaluated.

discuss

order

fennecfoxy|1 year ago

Many languages work like that and a lot of the issues people point out with JS are applicable to many scripting languages. Usually people point out Maths problems...aka problems with floats, which isn't really a JS problem.

People also point out stuff like `[]+[]` where Array addition operator is not overloaded to handle it at all because the correct way is to use `.concat` so I think by default duck typing comes into play and in most cases with that in JS the preferred type is string.

I do wish that there was a "cleaner" spec of JS that wasn't as backwards compatible but fixed all of the gotchas and filled in every gap but there doesn't seem to be much call for it atm.