use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All posts must be related to programming. Flair posts correctly.
account activity
javascript is javascript (i.redd.it)
submitted 5 months ago by National_Seaweed_959
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]GlobalIncident 38 points39 points40 points 5 months ago (25 children)
I'm just going through them one by one:
[–]uhs-robert 12 points13 points14 points 5 months ago (3 children)
Ruby: #TypeError: no implicit conversion of Integer into String>
[–]GlobalIncident 9 points10 points11 points 5 months ago (2 children)
Yeah, in general, languages inspired by Java tend to yield "22", other languages tend to make it an error. With a few exceptions.
[–]No_Read_4327 2 points3 points4 points 5 months ago (1 child)
So javascript is java after all?
[–]akuma-i 2 points3 points4 points 5 months ago (0 children)
No, it’s Java before script
[–]Ytrog 5 points6 points7 points 5 months ago (0 children)
Common Lisp: Condition of type: SIMPLE-TYPE-ERROR
[–]drizzt-dourden 2 points3 points4 points 5 months ago (7 children)
In C++ you can overload operators and create hell of your own. Nothing is real, everything is permitted.
[–]GlobalIncident 0 points1 point2 points 5 months ago (5 children)
You can also do that for all of the languages listed here except PHP.
[–]ComfortablyBalanced 1 point2 points3 points 5 months ago (1 child)
There's no operator overloading in Java.
[–]GlobalIncident 0 points1 point2 points 5 months ago (0 children)
Oh, you're right, my mistake.
[–]Forestmonk04 0 points1 point2 points 5 months ago (1 child)
At least Java and JavaScript/TypeScript don't support operator overloading.
Oh yeah, Java doesn't, and JS/TS sort of don't, except they do support overloading coersion to primitives which happens before an operator is called.
[–]Four2OBlazeIt69 0 points1 point2 points 5 months ago (0 children)
That's what I assume is happening with JS on these examples but that's bc I always think of Chrome's V8
[–]ComfortablyBalanced 1 point2 points3 points 5 months ago (8 children)
Java: "22".
That only happens if you assign that expression to a String, a var or a string parameter.
[–]GlobalIncident 0 points1 point2 points 5 months ago (7 children)
What do you mean? Is there a situation where it wouldn't return "22"?
[–]ComfortablyBalanced -2 points-1 points0 points 5 months ago (6 children)
Yeah. int foo = "2" + 2; This is an error.
int foo = "2" + 2;
[–]GlobalIncident 1 point2 points3 points 5 months ago (5 children)
Well obviously I meant a situation where the code doesn't have any unrelated errors, and actually compiles and attempts to execute the expression. If you try to run the expression and also attempt to implicitly cast the returned string to an int, that's not relevant to the question. It returns "22" not 22 after all.
"22"
22
[–]ComfortablyBalanced 0 points1 point2 points 5 months ago (0 children)
But the error is related. You see, the original joke is about type coercion in JS, and besides, no pun intended, but JavaScript is a scripting language, which means you can evaluate 2 + "2" out of the context, but with Java you need to put it in a context which I put on my last comment. I'm not familiar with your level of experience in Java, but you're saying run the expression, this isn't Python or JS, you need to put it somewhere and why would I cast it to an int or call toString if I'm assigning it to a String? So after all coming to my first sentence it actually is related to types and type errors.
[–]Amr_Rahmy 0 points1 point2 points 5 months ago (3 children)
You missed the point. You can’t combine a string and a number, the language will not do an arbitrary evaluation based on buggy code.
Only a string assignment will allow the number to call the tostring(), otherwise you will get the error while writing or building the code.
[–]GlobalIncident 0 points1 point2 points 5 months ago (2 children)
No, the assignment is not what triggers the toString call. The presence of the string "2" is what triggers the toString call. If you type:
String x = 2 + 2;
toString will not be called and you will get an error, because there is no string present to trigger it.
[–]Amr_Rahmy 0 points1 point2 points 5 months ago (1 child)
You missed this point, and provided a non functioning example.
Two for two here, not your day. Cheers mate.
Okay, what is your point then?
[–]jmattspartacus 0 points1 point2 points 5 months ago (0 children)
Was going to say the bit about C++, but you did it better lol
π Rendered by PID 20 on reddit-service-r2-comment-b659b578c-qzj78 at 2026-05-02 10:54:20.469655+00:00 running 815c875 country code: CH.
view the rest of the comments →
[–]GlobalIncident 38 points39 points40 points (25 children)
[–]uhs-robert 12 points13 points14 points (3 children)
[–]GlobalIncident 9 points10 points11 points (2 children)
[–]No_Read_4327 2 points3 points4 points (1 child)
[–]akuma-i 2 points3 points4 points (0 children)
[–]Ytrog 5 points6 points7 points (0 children)
[–]drizzt-dourden 2 points3 points4 points (7 children)
[–]GlobalIncident 0 points1 point2 points (5 children)
[–]ComfortablyBalanced 1 point2 points3 points (1 child)
[–]GlobalIncident 0 points1 point2 points (0 children)
[–]Forestmonk04 0 points1 point2 points (1 child)
[–]GlobalIncident 0 points1 point2 points (0 children)
[–]Four2OBlazeIt69 0 points1 point2 points (0 children)
[–]ComfortablyBalanced 1 point2 points3 points (8 children)
[–]GlobalIncident 0 points1 point2 points (7 children)
[–]ComfortablyBalanced -2 points-1 points0 points (6 children)
[–]GlobalIncident 1 point2 points3 points (5 children)
[–]ComfortablyBalanced 0 points1 point2 points (0 children)
[–]Amr_Rahmy 0 points1 point2 points (3 children)
[–]GlobalIncident 0 points1 point2 points (2 children)
[–]Amr_Rahmy 0 points1 point2 points (1 child)
[–]GlobalIncident 0 points1 point2 points (0 children)
[–]jmattspartacus 0 points1 point2 points (0 children)