#javascript #frontend
@CFDS the result of empty-array + array-with-two-empty-strings should be array-with-two-empty-strings. And not a string with one comma in it with no reason, which is beyond WAT. I got irritated when i saw that empty-array plus empty-array results in empty-string, which is already stupid as hell, but OK, its JS..¯\_(ツ)_/¯
But this? ... I dont know. Its creating commas out of thin air.. thats so stupid.
@CFDS See, even with an explanation, its still stupid as hell. Its so sad that this crap is still the same since https://www.destroyallsoftware.com/talks/wat
Why cast arrays to strings in the first place 🤷 why not type-error if `+` wants to see stringable things. Why does `+` want to see strings. Number+number is number, not number-as-string for example. Hach.
@CFDS well i hit this in a real-life project :)
There is nothing wrong with admitting that parts of a language suck btw... i did a lot of PHP, i have no problems with admitting that eg haystack-needle positioning inconsistency there is super stupid. Or GC..or speed.. Or Python, where the actual error in error reporting is often somewhere at ~3/4 of the 20-pages-long error message. Or Java where ..its Java. Golang and "exceptions"..
Dont feel attacked :) If you like JS, then thats good :)
@CFDS i think that this metaphor doesnt fit completely-legit expectations like "order of left and right operant shouldnt matter on + operator"
But its OK if we disagree :)
@leKnecht Your last example is actually demonstrating a gotcha in REPL/console, and not in JS per se.
"{} + []" can be interpreted as an expression OR as a statement. If it's an expression, the "{}" gets evaluated as an object. If it's a statement, the "{}" gets evaluated as an empty control block.
Different REPLs and consoles use different heuristics for figuring out whether the given line(s) are supposed to be a statement or an expression. This is the cause of seemingly different outcomes.
@CFDS ah! That does make sense. I was already puzzled, as explicit string casts stayed the same on browser and repl.
But i still think that some behaviors do have no benefit / use-case and create pitfalls, so raising errors would be better 🤷