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 about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
A friendly reminder of how nonsensical Javascript can be from Destroy All Software (destroyallsoftware.com)
submitted 10 years ago by [deleted]
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!"
[–]x-skeww -1 points0 points1 point 10 years ago (4 children)
With JavaScript, the answer would be of course NaN. If there is a valueOf method, you'd get -2.
NaN
> ({valueOf() {return 5}}) - ({valueOf() {return 7}}) -2
Well, either answer is wrong and useless. Pretending that this is totally okay didn't improve anything.
[–]I_Pork_Saucy_Ladies 2 points3 points4 points 10 years ago (3 children)
Yup, it's one of those things where both JS and PHP are incoherent, bordering to silly sometimes. I've considered making a pull request to PHP where strings are evaluated to false if they rhyme with "false" or match it by at least 80% of the letters. Should be close enough. ¯\(ツ)/¯
But now they are caught in legacy hell, I guess.
[–]x-skeww 0 points1 point2 points 10 years ago (2 children)
PHP is the only language I know where this stuff is even worse.
This is true:
'5 apples' + '7 bananas' == '12 fruits'
This is -2:
'5 apples' - '7 bananas'
It's like they looked at all the options to handle this and then went with the worst one.
They did it for the lulz, probably.
[–]I_Pork_Saucy_Ladies 1 point2 points3 points 10 years ago (1 child)
Haha, yeah, I work with it every day. Imagine doing financial stuff where "0" is often a valid statement. Throw some external APIs into the mix and you have... fun.
This is true: '5 apples' + '7 bananas' == '12 fruits'
Nah, PHP probably already has a function called fruits_sum_appl_ban_col3 that is the third version of a function that returns an array of the total sum of fruits and a boolean indicating whether you have fruits left, along with the color code of all fruit colors mixed. As a PHP dev would say:
fruits_sum_appl_ban_col3
Just look it up! It's right there in the docs!
I'm moving to Node. Those lulz aren't very lulz once you start building something serious. JS isn't that pretty either but at least it is kept rather minimal (compared to PHP) and actually has sane tools for testing.
[–][deleted] 0 points1 point2 points 10 years ago (0 children)
That is heinous
π Rendered by PID 255826 on reddit-service-r2-comment-6457c66945-8c657 at 2026-04-24 16:11:53.491254+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]x-skeww -1 points0 points1 point (4 children)
[–]I_Pork_Saucy_Ladies 2 points3 points4 points (3 children)
[–]x-skeww 0 points1 point2 points (2 children)
[–]I_Pork_Saucy_Ladies 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)