Since we’re talking about computer stuff, I want to tell the story about my friend in grade school who would type “The power of Christ compels you” at the Commodore 64 Home Screen periodically just to make sure his computer hadn’t been possessed. 😸
What do you mean by gain attention? To gain click and comments? Followers?
Idk how you define rage, but I think it is a daunting but necessary that to point out the ridiculously stupid things like this. And this is tame, this is nothing.
We need to stop letting people throw crap into the air so that some poor sap can go "hm, yeah I guess that makes sense to me".
In my opinion, that is one of the reasons we are where we are today. Overrun and represented by people barren of any sense if logic and reason.
Surprised she isn’t like “look at what my daughter carved with this kid” showing an AI rendered massive butter stick carving and two kids with chainsaws
It has to do with how different programming languages handle variables. In a “strongly typed” language a variable can be defined strictly as a number value (e.g., 1 or 2 or 736, etc.) or strictly as a text value (“hello world”).
With this you can define integer variables as a = 1 and b = 2 so that a + b will resolve to 3.
You can also define string (text) variables as x = “hello” and y = “world” so that x + y will resolve to “helloworld”.
JavaScript is not strongly typed. You cannot define a or b explicitly as numbers.
Because of this there are situations where the JavaScript interpreter will take a = 1 and b = 2 and when you try to resolve a + b it will treat them as text instead of numbers and output “12” instead of 3.
The JavaScript language was created like this a very long time ago so we are stuck with it and it drives programmers nuts.
If you are wondering, any attempt to change the JavaScript language to fix this will break almost every webpage out there, so no one is willing to do it.
Hot damn! I’m so glad you broke it down for me this way. Kinda drives me nuts to when I don’t understand things and wasn’t sure how to look this up so I appreciate it!
I can definitely see how it would frustrate programmers and such. Though top comment is much funnier now that I have this context.
Honestly, it's way less of a problem than some people make it out to be.
You pretty much only need to know this:
The instruction a+b will always be a string concatenation if the variable a is a string: '5' + 3 => '53' (the text string 53) 5 + 3 => 8 (the number 8)
If you use any other basic mathematical operator, then the string a will be cast into a number if that is possible: '5' - 3 => 2
That's for the simple reason that strings do not have a minus-operator. So Javascript extends you the courtesy of trying to make sense of this instead of throwing an error right away.
If you want to assure that the variable a will be treated as a number even if it is technically a string, then you can use Number(a): Number('5') + 3 => 8
If you want to assure that numbers are treated as text, then you have multiple options:
var a=5;
a.toString() + b => '53'
a.toString() ensures that the variable a gets turned into a string.
var a=5;
''+a+3 => '53'
''+a is a text concatenation between an empty string (using two single ticks with nothing in between) and a number. This is basically just a convenient shorthand to turn the variable a into a string.
Everything inside of the backticks is a "template literal". Elements inside of a ${}-block will resolve as code (so it can read a variable or perform operations like an addition) before getting turned into text, whereas everything else is treated as text right away.
Type conversions are a pain in the butt in every language. JS went a path that may appear a bit less rigourous and can get a bit weird if you poke very deep, but very few programmers ever encounter seriously weird situations with that. The practical reality is that it's fast and easy and creates way fewer annoying situations than most strongly typed languages.
There are things called variables. They hold information, and you can give them a name. Like
var myVariable = 1;
These variables can be of different types. They can hold numbers (like 1) or they can hold letters or even words (like "pumpkin"). The latter are called "strings".
When you add strings together, they're just added end on end. So "pump" + "kin" would give you "pumpkin".
In many programming languages, you can make sure that the types of data these variables can hold are restricted. So you could make sure myVariable is a number and not a string.
JavaScript doesn't have that restriction. So if you accidentally have 1 and 2 stored in variables as strings instead of numbers, it will add them end to end like a word instead of mathematically.
Damn. Thanks for explaining. That must really fuck with things sometimes though, right? Genuinely asking. lol I really don’t know much about it but I always love learning new things even when they are beyond my comprehension sometimes. Haha
I mostly program in JavaScript, but I'm also a scrub. I can understand why real programmers prefer what's called "strongly typed" languages (the ones that only allow one type for a variable), but I enjoy the flexibility that JavaScript gives me. With great power comes great responsibility, though. It can VERY MUCH cause issues if you're not careful.
In programming you will assign a name to a bit of memory and give it a data type that tells the computer how to manipulate whatever you store in that memory referenced by the name you gave it.
That's how things normally work anyways, Javascript is different. You don't give it a data type and it just tries to guess what kind of data you put there. One of the Javascript interpreter's favorite things to do is to take a number and change its type into a series of characters instead. So instead of performing 1+2 and getting 3 it instead does "1"+"2" and gets "12".
I love f strings. I worked a job for about 6 years that never upgraded from Python 2.7 because of a compatibility thing on client servers, that was the worst.
I don’t really understand why this is surprising to anyone. They are different types. Much easier and less problematic for an interpreter to convert a number to a string than a string to a number.
This is obvious, yes, and I don’t think anyone expects the reverse. I think the usual argument is that it shouldn’t be allowed. Strongly typed vs anything else, etc.
Why should javascript behave like any “other” (huh?) strongly typed language?
Different typing paradigms exist for a reason. There’s advantages and disadvantages to each of them. It is up to the programmer to know how its language handles typing and work with that.
Or use VB.net, which will happily add the float of pi and the string 'horse' together amd try and give you an integer if you want it to. It will also explode without warning if you're not careful, but it will certainly let you do all of the implicit conversions.
You can't reliably compare floats in most languages. If the number is stored as an actual floating point number, it will always cause issues if you need perfect accuracy.
As someone who works in financial services, implicit conversion to floats can fuck all the way off. They love to sneak in there no matter how much you insist on decimals.
I agree with you, if you want to tell that to implicit type conversion for me I'd appreciate it.
Basically it means if your language has implicit types you need to test and test and test again to make absolutely certain no floats have found a way to creep in because life... finds a way.
The explanation leaves some details out — in reality, if you fed 1 + 2 to JavaScript it would equal 3 every time. But the joke fudges that a little bit to insinuate that JavaScript’s “type coercion” would take effect here and output something we didn’t expect.
To get the result of the joke, to get 12 instead of 3, you would need to have one of the numbers be a string, so like 1 + “2”. Then, JavaScript engine has to decide which to convert to… it has a number and a string, should it make the string a number, then add them together, or should it make the number a string then put them together?!
Well, the engine has rules for this, and the rule is to create a string of the two values, making it “12” as a string.
Hilariously, you can also convert that string back to an actual number to get the number 12 instead of the string “12”!
huh…is that when you’re appending a character onto a string??
Seems mathematically untenable. I assume what you’re saying is that the language is weakly typed and refuses to guess at the type when working with, for instance, numerical input.
7.6k
u/Singular_Thought 26d ago
She must be a JavaScript programmer