Sadly the problem is that the old men are the ones who know how to use the JavaScript and the young men are the ones who have no fucking clue what they’re doing anymore.
People are supposed to understand this kind of “logic”? No wonder everything is full of bugs if code is THAT obscure. You seem to even like it that way.
Watch this talk, it’s funny and explains this well; this isn’t a good thing in anyone’s opinion, it’s just a demonstration of one of many unfortunate design choices in the JavaScript programming language:
https://www.destroyallsoftware.com/talks/wat
Javascript has a tendency to “just work” even when it might be a better idea not to. That is achieved by making assumptions and defaulting to certain pre-defined behaviors where most other languages would just stop. Unless something truly catastrophic happens, JS always tries to find a way to keep the code running. Good or bad, that’s by design just how it works.
That is an example of this tendency. Normally the " ‘a’ + + ‘a’ " bit should be an error case, because that does not make sense. Where most programming languages would throw and error and stop execution, javascript just soldiers on. It assumes the center bit is an addition of numbers. Except since there’s no number there, it automatically injects the value that represents invalid numbers, which is “nan” for “not a number”. Then, since that “number” is surrounded by letters, it parses that number into a text value, which is the string “nan” itself. And then finally it adds all the letters together to form a banana.
There are plenty of weird ways to get JS to give you stupid results back. Shit like these are not bugs with the language, it’s just JS working as intended. Except the way language works as intended can lead to actual bugs very easily, is the problem.
document.write(('b' + 'a' + + 'a' + 'a').toLowerCase());
This outputs “banana”
*old man yells at javascript*
Sadly the problem is that the old men are the ones who know how to use the JavaScript and the young men are the ones who have no fucking clue what they’re doing anymore.
People are supposed to understand this kind of “logic”? No wonder everything is full of bugs if code is THAT obscure. You seem to even like it that way.
Watch this talk, it’s funny and explains this well; this isn’t a good thing in anyone’s opinion, it’s just a demonstration of one of many unfortunate design choices in the JavaScript programming language: https://www.destroyallsoftware.com/talks/wat
Oh god, no, everyone hates Javascript, the most-used programming language in the world. Paradoxical but true.
Tbh js is pretty pleasant to write with typescript, though is it even considered the same language? It is a superset.
Could someone explains this to some of us who haven’t learnt these cancer yet?
Watch this talk, it’s funny and explains this well; https://www.destroyallsoftware.com/talks/wat
Javascript has a tendency to “just work” even when it might be a better idea not to. That is achieved by making assumptions and defaulting to certain pre-defined behaviors where most other languages would just stop. Unless something truly catastrophic happens, JS always tries to find a way to keep the code running. Good or bad, that’s by design just how it works.
That is an example of this tendency. Normally the " ‘a’ + + ‘a’ " bit should be an error case, because that does not make sense. Where most programming languages would throw and error and stop execution, javascript just soldiers on. It assumes the center bit is an addition of numbers. Except since there’s no number there, it automatically injects the value that represents invalid numbers, which is “nan” for “not a number”. Then, since that “number” is surrounded by letters, it parses that number into a text value, which is the string “nan” itself. And then finally it adds all the letters together to form a banana.
There are plenty of weird ways to get JS to give you stupid results back. Shit like these are not bugs with the language, it’s just JS working as intended. Except the way language works as intended can lead to actual bugs very easily, is the problem.
Okay thanks for this info. So we got ba and nan and then aa, which is bananaa, not banana?
Jesus, I thought you made a typo until I tried it. Gotta love those unary operators…