JavaScript
-
This post did not contain any content.
-
This post did not contain any content.
Lets fix it. I think that since we are removing the ones, then "11" - 1 should be equal to "".
-
This post did not contain any content.
[object Object][object Object]
-
This post did not contain any content.
-
This post did not contain any content.
People that try to do mathematical operations with strings blaming the programming language that had a stated design goal to do its best and try to keep running scripts that make no sense because they realized it would be used by people that have no idea what they are doing. Clearly they were right.
-
Lets fix it. I think that since we are removing the ones, then "11" - 1 should be equal to "".
Should it, or should it be "1"? (just removing one, one)
-
This post did not contain any content.wrote on last edited by [email protected]
This is too stupid so I had to check.
Fuck me.
-
This post did not contain any content.
-
This is too stupid so I had to check.
Fuck me.
wrote on last edited by [email protected]Hm, playing devil's advocate, I think it is because the minus has not been defined as a string operation (e.g. it could pop the last char), so it defaults to the mathematical operation and converts both inputs into ints.
The first is assumed to be a concat because one of the parcels is a string...
It's just doing a lot of stuff for you that it shouldn't be in first place 🤭
-
This is too stupid so I had to check.
Fuck me.
Unfortunately, it makes sense if you know what + means, which is concatenate. - is strictly a math function though.
Not saying that makes this better. It just makes sense.
-
Unfortunately, it makes sense if you know what + means, which is concatenate. - is strictly a math function though.
Not saying that makes this better. It just makes sense.
wrote on last edited by [email protected]It's an issue with most if not all languages that aren't strongly typed.
-
wrote on last edited by [email protected]
This is a really good interview, and does a good job highlighting Javascript's biggest strength: it's flexibility.
“It was also an incredible rush job, so there were mistakes in it. Something that I think is important about it is that I knew there would be mistakes, and there would be gaps, so I made it very malleable as a language.”
He cites the “discovery” of asm.js inside of JavaScript, calling it “another thing I’m particularly proud of in the last 10 years.” It uses the bitwise operators that were included in the original JavaScript which are now the basis for a statically-typed language with machine types for high-speed performance. “If it hadn’t been in there from 1995, it would’ve been hard to add later. And the fact that it was there all along meant we could do incredibly fast JavaScript.”
He tells InfoWorld it’s “this very potent seed that was in the original JavaScript from the 10 days of May in 1995.” JavaScript’s 32-bit math operators (known as bitwise operators) trace their lineage all the way back to the C programming language — and to Java. This eventually led to WebAssembly — a way to convert instructions into a quickly-executable binary format for virtual machines — and the realization that with a JavaScript engine, “you can have two languages — the old language I did with the curly braces and the functions and the shift operators, and this new language which is a binary language, not meant for reading by humans or writing. But it can be generated by compilers and tools, and can be read by tools…”
-
Hm, playing devil's advocate, I think it is because the minus has not been defined as a string operation (e.g. it could pop the last char), so it defaults to the mathematical operation and converts both inputs into ints.
The first is assumed to be a concat because one of the parcels is a string...
It's just doing a lot of stuff for you that it shouldn't be in first place 🤭
Yup. It's completely inconsistent in its interpretation of the + operator.
-
Yup. It's completely inconsistent in its interpretation of the + operator.
wrote on last edited by [email protected]Yeah, I actually had to try 1+"11" to check that it didn't give me 12, but thankfully
it commutesit's consistent -
This is too stupid so I had to check.
Fuck me.
Fuck me.
-
Yeah, I actually had to try 1+"11" to check that it didn't give me 12, but thankfully
it commutesit's consistentit commutes
Maybe the behaviour with regard to type conversion, but not for the operation itself.
"13"+12 and 12+"13" don't yield the same result.
-
Unfortunately, it makes sense if you know what + means, which is concatenate. - is strictly a math function though.
Not saying that makes this better. It just makes sense.
wrote on last edited by [email protected]It is 'comprehensible' in the sense that it's possible to figure out how it happened, but it absolutely does not "make sense" in terms of being a reasonable language design decision. It's 100% incompetence on the part of the person who created Javascript.
-
Should it, or should it be "1"? (just removing one, one)
Which "1" did it remove? And did it search the string to find a "1" to remove, or did it remove whichever character happened to be at array index 1?
-
People that try to do mathematical operations with strings blaming the programming language that had a stated design goal to do its best and try to keep running scripts that make no sense because they realized it would be used by people that have no idea what they are doing. Clearly they were right.
the programming language that had a stated design goal to do its best and try to keep running scripts that make no sense...
...itself makes no sense. It is wrong and bad that Javascript was ever designed that way in the first place.
-
This is too stupid so I had to check.
Fuck me.
I think I'm on the side of "if you do this in your code, you deserve what you get."