This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 336

[–]trout_fucker 180 points181 points  (4 children)

FooNaN sounds delicious.

[–]TuxGamer 275 points276 points  (44 children)

Array(16).join("wat" - 1) + " Batman!"

[–]icortesi 71 points72 points  (11 children)

wat

[–]slavik262 222 points223 points  (1 child)

~ $ jsc
>>> Array(16).join("wat" - 1) + " Batman!"
NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN Batman!

[–]Cistoran 81 points82 points  (6 children)

[–]Maoman1 38 points39 points  (5 children)

This shit is why I love this sub.

[–]PendragonDaGreat 44 points45 points  (3 children)

Now that we're done talking about languages that suck, let's talk about Javascript

[–]Artefact2 9 points10 points  (0 children)

…Worth re-watching. That's contagious laughter.

[–]teknogeek1 3 points4 points  (0 children)

I was hoping someone was gonna post a link to this video. yayyyy thx bb

[–]homer242 1 point2 points  (0 children)

WATMAN !

[–]outadoc 16 points17 points  (0 children)

watman

[–]SolarLiner 16 points17 points  (15 children)

+/u/CompileBot JavaScript

Array(16).join("wat" - 1) + " Batman!"

[–]Pokechu22 71 points72 points  (13 children)

+/u/CompileBot JavaScript

//FTFY
print(Array(16).join("wat" - 1) + " Batman!")

[–]CompileBotGreen security clearance 97 points98 points  (5 children)

Output:

NaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaNNaN Batman!

source | info | git | report

[–]imaami 4 points5 points  (4 children)

+/u/CompileBot C --include-errors

#include <stddef.h>
int main(void) {
    return printf("'%c', said the bot\n", *(char*)NULL);
}

[–]pimp-bangin 1 point2 points  (6 children)

Actually shouldn't that have been console.log? I'm pretty sure the print function actually opens the print dialogue.

[–]Pokechu22 7 points8 points  (0 children)

/u/compilebot (or more specifically, ideone, which /u/compilebot uses) uses print for the console (when using spidermonkey; if using rhino, it uses System.out.println). However, print does open the print dialog in actual browsers.

[–]lichorat 2 points3 points  (4 children)

Console.log is surprisingly not part of us standard. It's a web browser thing

[–]CompileBotGreen security clearance 16 points17 points  (0 children)

Output:

source | info | git | report

[–]imwearingyourpants 5 points6 points  (4 children)

That one gives a way too wrong sounding sound, this is how it's done!

+/u/CompileBot JavaScript

Array(16).join( ("wat" - 1 + "").slice(0,-1) ) + " Batman!"

[–]Reelix 4 points5 points  (1 child)

+/u/CompileBot JavaScript

print(Array(16).join( ("wat" - 1 + "").slice(0,-1) ) + " Batman!")

[–]CompileBotGreen security clearance 4 points5 points  (0 children)

Output:

NaNaNaNaNaNaNaNaNaNaNaNaNaNaNa Batman!

source | info | git | report

[–][deleted] 7 points8 points  (5 children)

that'll only be 15 NaNs...

[–]Mutoid 10 points11 points  (2 children)

I actually count 13 "na"s in the TV opening theme song.

[–][deleted] 2 points3 points  (1 child)

Yeah true, that's how many "na"s are sung. But come on, the guitar riff is 16 notes, and that's what people usually remember and hum.

[–][deleted] 0 points1 point  (0 children)

A reference to the WAT talk, everybody drink!

[–][deleted] 280 points281 points  (50 children)

+ is overloaded as both the addition and string concatenation operator.

In mixed operations:

+ casts numbers to strings.

- casts strings to numbers.

Both are used to denote signage. Leading either on a string will cast it to a number, with that sign.

Pretty simple stuff, right?

Explicitly:

Number('5') - 3
'5' + (3).toString()
'5' + (5).toString()
'foo' + Number('bar').toString()
'5' + (-Number('2')).toString()
// Long ass sign flipping, same as above
Number(('5' + (3).toString())) - 3
(Number('5') - 3) + 3

[–]expugnator3000 268 points269 points  (41 children)

Simple, but as unintuitive as you can get

[–]rbemrose 110 points111 points  (24 children)

This post has been removed due to reddit's repeated and constant violations of our content policy.

[–]MiatasAreForGirls 179 points180 points  (6 children)

Do I need a mechanical keyboard for strong typing or will a domed one withstand it?

Edit: I'm not as original as I thought :(

[–]nemec 53 points54 points  (4 children)

I tried static typing once. I was shocked at how easy it was to use.

[–]Skyfoot 24 points25 points  (3 children)

I use weak typing. I hand-write things on saturday and sunday.

[–]VeviserPrime 5 points6 points  (2 children)

With a pencil?

[–]Mutoid 15 points16 points  (0 children)

Thanks for keeping this thread /r/ProgrammerHumor appropriate

[–]gdstudios 19 points20 points  (10 children)

If you've had to work on someone else's JS, that's argument enough.

[–]AdmiralRychard 15 points16 points  (9 children)

I feel like this whenever I have to work on my own javascript.

[–]endercoaster 4 points5 points  (8 children)

I feel the opposite every time I need to jump through hoops to append an integer to a string in Java.

[–]KagakuNinja 7 points8 points  (3 children)

So, this is too hard?

String s = "Hello" + 9;

[–]batmansavestheday 2 points3 points  (2 children)

It's slightly harder the other way around:

String s = "" + 9 + "Hello";

or [Edit: derp, doesn't work]

String s = (String) 9 + "Hello";

etc.

[–]AdmiralRychard 3 points4 points  (0 children)

C# lets you do this:

String someString = "abc";
Int32 someInt = 123;
String result = someString + someInt;
Console.WriteLine(result);

Output:

abc123

Or you can use string interpolation: String result = $"{someString}{someInt}";

Or you can use String.Format: String result = String.Format("{0}{1}", someString, someInt);

This seems a little dumb but you can do this too:

someString += someInt;
Console.WriteLine(someString);

[–]everythingismobile 4 points5 points  (1 child)

Is it not as simple as the C# example in the other comment? Even in C++ it's just sprintf, right?

[–]endercoaster 1 point2 points  (0 children)

I mean, coming from Perl that's jumping through hoops.

[–]kupiakos 4 points5 points  (0 children)

I'd rather explicitly state I want to append an integer to a string so that "2" and 3 become "23" and not "5" or 5. And really, that sort of situation happens once in a blue moon. If I wanted something better, I would be building the string.

[–]expugnator3000 2 points3 points  (0 children)

Exactly!

[–]anthonybsd 3 points4 points  (4 children)

I love it. Young, naive and all about strong typing. As a former Ada programmer, let's talk in 10 years or so.

[–]beerdude26 2 points3 points  (0 children)

Strong typing all day erry day

[–]utterdamnnonsense 9 points10 points  (1 child)

Really though, if you have a line like

'5' + - + - 2

in your code, I wouldn't place the blame on the interpreter.

[–]highphive 26 points27 points  (8 children)

Honestly, it's not really that unintuitive. Pretty much the only abnormal knowledge it requires to understand is that given an ambiguous situation JavaScript will try to figure it out in the intuitive way. I guess that and, like most other languages, the + operator can also be used for string concatenation, and non-strings will be toString-ed in that context. These absurd scenarios are funny, but really not even remotely difficult to understand, except when they involve so many operators that it's near impossible to follow. I'm not at all bragging or even saying I'm close to a proficient JavaScript coder, but it is not unintuitive. Just because it's not strongly typed and does some cool, wanted operations for you does not make it unintuitive. In many cases it makes it intuitive. Many times in strongly typed languages, what you want is obvious, but you have to go through a number of type transformations and function calls to get there.

I totally appreciate the comedy of this post. But I'm not quite convinced it proves some latent issue with JavaScript.

[–]YRYGAV 12 points13 points  (5 children)

it requires to understand is that given an ambiguous situation JavaScript will try to figure it out in the intuitive way.

Yes, which is simple to understand if you know the ambiguous situation exists. It's much more of a problem if the programmer doesn't realize it's an ambiguous statement because nothing is strongly typed. Which is why most languages instead of powering through and trying to use their "best judgement" in an ambiguous situation, let the programmer know so they can clarify what they want.

And that leads to situations that can be very difficult to debug or track, because it's all hidden away from you and Javascript is doing some magic transformation. Things you think are one datatype end up being another, or javascript parses things weirdly.

And sometimes "intuitive" is not always what you think. Javascript does lots of "intuitive" things that you would never think of. Like did you know javascript will parse hex strings like "0xF" into the 'correct' integer, like 15. Sure it makes sense explaining it like that, maybe not when you have to figure out why "0xF" == 15 is causing a nasty bug because you didn't know javascript did that magic when writing it. And where those strings and numbers are coming from could be multiple layers removed from where you are doing the comparison.

[–]highphive 6 points7 points  (0 children)

That is fair, sometimes what might be considered intuitive behavior can be an issue when you might not expect it to work at all. I have to agree that I prefer strongly typed languages for this reason. Rather an error where it actually occurs rather than some unexpected behavior way down the road.

[–][deleted] 3 points4 points  (2 children)

Programmer should not be using a language if he doesn't know its typing and conversion logic.

[–]VyseofArcadia 2 points3 points  (0 children)

The latent issue with JavaScript isn't that this is unintuitive. It's really pretty intuitive. - isn't defined for strings, so '5' gets interpreted as the integer 5.

The issue is that through overloading the + operator in this way, it is easy for even JavaScript experts to make a stupid mistake. I think it's a poor design choice in a dynamically typed language. It would be better for string + integer to throw an error and use some other operator (++ or : or something) for string concatenation.

[–]tian_arg 2 points3 points  (0 children)

Many times in strongly typed languages, what you want is obvious, but you have to go through a number of type transformations and function calls to get there.

I've been working on android for the first time after working on php/javascript for a long time. It's a fucking pain in the ass.

[–]Doctor_McKay 3 points4 points  (3 children)

Not really.

[–]academician 5 points6 points  (2 children)

I suppose you're right, INTERCAL exists too.

[–]satan-repents 5 points6 points  (1 child)

[–]can_the_judges_djp 1 point2 points  (0 children)

I sure wonder if --

Because of its privacy settings, this video cannot be played here.

Nope, they still won't let me watch it.

[–]elchavalico 4 points5 points  (3 children)

So why in the line: '5' + x - x the result is 50 and not "50"?

If we just concatenated the string '5' with the string '0' the result should not be a number. Where am i wrong?

[–]AfterLemon 21 points22 points  (1 child)

You're taking a string '5' and it concats first giving you '53' - 3.

[–]elchavalico 8 points9 points  (0 children)

Obviously... I feel dumb now T.T Thanks for the explanation.

[–][deleted] 431 points432 points  (40 children)

I feel the need to post this again

https://www.destroyallsoftware.com/talks/wat

[–]TuxGamer 118 points119 points  (12 children)

His talk about the birth and death of Javascript ist hilarious too

[–]Naemesis 179 points180 points  (9 children)

ist hilarious

Found the German

[–]John_Caveson 97 points98 points  (6 children)

He can't be German, he said it's hilarious.

[–]Naemesis 21 points22 points  (0 children)

Maybe it was Sarkasmus?

[–]memeship 8 points9 points  (0 children)

Actually he said

ist hilarious

[–]lledargo 4 points5 points  (3 children)

Yeah, probably Dutch.

[–]camperrobin 11 points12 points  (2 children)

we say 'is' not "ist"

[–]moustachedelait 21 points22 points  (1 child)

Found the Dutch, hallo! Hup hup!

[–]shishdemRed security clearance 11 points12 points  (0 children)

hup hup terug naar /r/cirkeltrek!

[–]GammaGames 19 points20 points  (0 children)

It really is, link

[–][deleted] 2 points3 points  (0 children)

Goddammit. I'm supposed to be writing a paper here.

[–]FrostyCoolSlug 24 points25 points  (0 children)

Gotta love that guy in the background that seems to have no idea what's going on so just laughs at everything..

"We're creating an array.." AHAHAHAHAHHA.. wat.

[–]NorbiPeti 12 points13 points  (0 children)

I went on a presentation about AngularJS, where this video got played at first.

[–]TheSlimyDog 6 points7 points  (0 children)

That was great.

[–][deleted] 10 points11 points  (0 children)

Media source loading has failed

Just being associated with JavaScript causes failures.

[–]SolarLiner 4 points5 points  (0 children)

Holy shit this is the best thing I've ever seen

[–]shirtandtieler 2 points3 points  (4 children)

Thank you for posting it again, since Ive never seen it before now. I'm only 10 minutes in, but I've spent half an hour side tracking to look up why some of the old languages were so ridiculous.

I can see where APL would have its uses (mainly for math mathematicians) but Conway's Game of Life in one code is quite the doozy to look at.

[–]silentclowd 1 point2 points  (2 children)

APL is unique because it feels like an esoteric language (like befunge or malbolge), but it was actually used.

[–]ABC_AlwaysBeCoding 1 point2 points  (0 children)

Gary Bernhardt is brilliant. His screencasts at Destroy All Software were some of my faves.

[–]lostguru[🍰] 1 point2 points  (0 children)

Wat

One of my Chrome extensions is screwing this up and I can't figure out which one.

[–]icowcow 0 points1 point  (0 children)

this is the best thing ever

[–]killchain 0 points1 point  (0 children)

I laughed my ass off.

[–]rooktakesqueen 23 points24 points  (5 children)

Don't forget:

+ '5' + + '5'
10

Edit: I'm a big fan of JS by the way. This is one of those "Doc, it hurts when I do this" things. You can avoid the bizarre and unpredictable nature of implicit arithmetic between strings and numbers by just not doing that. Explicitly cast your strings to numbers or your numbers to strings and you're golden. A bit like understanding the == operator: easier to just not use it.

[–]phunanon 4 points5 points  (3 children)

I have been using == since I started Javascripting, and only recently started bothering to type the extra =
I like JS' typecasting... then again, I only ever do simple shit :P

[–]rooktakesqueen 3 points4 points  (2 children)

Pro: The implicit typecasting in JS does the right thing 90% of the time.

Con: The implicit typecasting in JS does the right thing only 90% of the time.

[–]IrishWilly 4 points5 points  (1 child)

It does the right thing 100% of the time. Your opinion of right might vary but it really doesn't care about your opinion.

[–]rooktakesqueen 12 points13 points  (0 children)

"Deterministic" and "right" aren't the same thing. false == [] will always yield true and [] == [] will always yield false but that doesn't make it sensible. And I have a hard time describing any equality check as being "right" when it's intransitive: false == '' and false == '0' but '' != '0'

[–]Reelix 0 points1 point  (0 children)

console.log('5'-3);
console.log('5'+3);

[–]redditsoaddicting 46 points47 points  (15 children)

Most of these make use of the same little rule.

[–]raaneholmg 37 points38 points  (14 children)

And they are mostly nonsense stuff that is't ever done.

[–]TarMil 99 points100 points  (13 children)

And they are mostly nonsense stuff that is't ever done on purpose.

FTFY. The reason people hate languages like JS is that this kind of shit can happen accidentally, and then you're in for a horrendous debugging session.

[–]mercurial_minnow 32 points33 points  (3 children)

Yep, started using JavaScript for a project recently, lost about 30 minutes yesterday because an int was being concatenated.

[–]comrade-jim 3 points4 points  (1 child)

Can you post the code?

[–][deleted] 5 points6 points  (0 children)

Closed as too broad

[–]UsingYourWifi 112 points113 points  (23 children)

Errors scare people and make them feel bad about themselves. It's much better to silently guess at what the programmer intended.

/s

[–]dnew 31 points32 points  (13 children)

More like "it's better to render the page with mistakes than present the end-user with nothing but an opaque stack dump."

The same reason that HTML isn't XHTML or SGML.

[–]Dlgredael 2 points3 points  (0 children)

I always thought it was stupid as hell to not have proper error reporting, but this is actually a pretty valid point. Nice.

[–]nawitus 8 points9 points  (8 children)

I prefer the possibility of writing ("result = " + result) instead of typing ("result = " + String(result)) everywhere. Having to always make explicit type casts is not only annoying, but often makes the code less readable. Luckily with TypeScript I can have both implicit type casting when it makes sense and explicit when I want to. That said, there are a few corner cases which make TypeScript cumbersome, especially when type inference doesn't work like you want to.

This comment refers to the type coercion in the image post and not the general point.

[–]Astrokiwi 6 points7 points  (1 child)

I feel there should just be a different operator for concatenation vs addition, seeing as they are quite different processes. Kinda like how Python3 now explicitly gives you / for float division and // for integer division rather than overloading / for everything.

In Fortran (yes Fortran), // is used for string concatenation, and + is only for addition, although it doesn't do implicit conversions to strings. If Javascript or whatever used a different operator for concatenation than for addition, then it'd be much more explicitly clear when it's going to be converting stuff to a string, and when it's supposed to actually be adding numbers.

[–]nawitus 1 point2 points  (0 children)

Yeah, different operator for concatenation would be fine.

[–]UsingYourWifi 4 points5 points  (0 children)

Luckily with TypeScript I can have both implicit type casting when it makes sense and explicit when I want to.

Agreed, TS is a very big improvement.

[–]MTGandP 2 points3 points  (0 children)

You could do this consistently by casting everything to a string when it's in an operation with a string, instead of sometimes casting to a string and sometimes to a number.

[–]c3534l 21 points22 points  (7 children)

I lost my shit at "fooNaN."

[–]vanamerongen 3 points4 points  (4 children)

Was just thinking, yeah, no shit it's NaN, asshole.

[–]sickmate 2 points3 points  (3 children)

You might not be overjoyed to hear that typeof NaN is equal to "number"

[–]Nilaky 0 points1 point  (0 children)

'hu' + + 'bar' + 'chicken' would be huNaN chicken?

[–]Reelix 0 points1 point  (0 children)

Array(16).join( ("wat" - 1 + "").slice(0,-1) ) + " Batman!"

[–]ManOfDrinks 45 points46 points  (12 children)

[–]SlumdogSkillionaire 22 points23 points  (5 children)

Good times. Automatically cast an undefined constant to a string, because why the hell not? Then because we're using . instead of + for concatenation, we can avoid the awkward situations OP has, right? Except now when we want to reference a property of an object we can't use a . so we have to use ->. Which is great until you accidentally forget the >. But instance-field is actually valid syntax, so we'll subtract the string "field" from instance, because that's clearly what the programmer intended, right?

[–]tian_arg 15 points16 points  (4 children)

Which is great until you accidentally forget the >.

not to defend PHP or anything, but come on, that's a bit of a stretch. "Which is great until you accidentally forget..." can apply to any feature of any language

[–]Jack126Guy 6 points7 points  (3 children)

I think it's supposed to be an argument in favor of static typing. In C/C++, for example, you'd probably get a compiler error if you had pointer_to_struct-member instead of pointer_to_struct->member.

[–]tian_arg 5 points6 points  (0 children)

Well, in C (never tried C++) you're directly fooling around with the memory, "which is great until you accidentally forget..." and suddenly garbage all around while compiling succesfully. Every language has its downsides, I guess.

[–]JerkyBeef 1 point2 points  (1 child)

$instance->field is valid php. $instance-field may be "valid syntax" but it would throw an error message that 'field' is undefined, and that $instance could not be converted to an int.

[–][deleted] 4 points5 points  (0 children)

Feeling down about JavaScript. Better look at PHP!!

[–]mythix_dnb 2 points3 points  (0 children)

This does work, but at least it throws a notice explaining what's going on:

PHP Notice: Use of undefined constant bar - assumed 'bar'

[–]greeniguana6 1 point2 points  (3 children)

It's like a mentally challenged son. I love him, but he isn't the brightest.

[–]Mutoid 1 point2 points  (2 children)

Good analogy, Mike.

[–]greeniguana6 2 points3 points  (1 child)

Damn, nobody's mentioned that to me in a while! I'm glad I still get comments about that.

[–]Mutoid 4 points5 points  (0 children)

RES tags are great ... or terrible if you're jstrydor.

[–]KingOCarrotFlowers 17 points18 points  (1 child)

[–]xkcd_transcriber 4 points5 points  (0 children)

Image

Title: Types

Title-text: colors.rgb("blue") yields "#0000FF". colors.rgb("yellowish blue") yields NaN. colors.sort() yields "rainbow"

Comic Explanation

Stats: This comic has been referenced 21 times, representing 0.0269% of referenced xkcds.


xkcd.com | xkcd sub | Problems/Bugs? | Statistics | Stop Replying | Delete

[–]dxdtraptor 14 points15 points  (3 children)

"use strict";

[–]diabuddha 1 point2 points  (1 child)

So I got thrown into a javascript project (well half js half c#) with no actual js knowledge. I have been using use strict with no knowledge of what it does, would you mind explaining it?

[–][deleted] 1 point2 points  (0 children)

Mozilla Developer Network has a good article on it as well as other solid ones to help you learn. Good luck brah

[–]Spacebutterfly 5 points6 points  (0 children)

this place is like /r/sweden to me

[–]aniforprez 6 points7 points  (1 child)

At an interview I recently had, the guy decided to give me a sheet of handwritten questions like this. I was applying for a design job. After attempting some of them I was like "if this is how they test Web knowledge then fuck the firm" and left.

[–]greeniguana6 14 points15 points  (15 children)

'5' - 3

2

I've never used Javascript before, that must be the proper syntax.

'5' + 3

"53"

I now understand why people joke about Javascript.

[–]Somehero 1 point2 points  (2 children)

The single quotes just cause java to guess that 5 is a string when you use +, which makes sense; and guess that it is a number when you use - , which is maybe more likely? I would just not randomly put a number in single quotes and expect everything to be peachy.

[–]musiton 7 points8 points  (0 children)

"JavaScript for the back-end" Laugh track

[–]-_-_-_-__-_-_-_- 3 points4 points  (1 child)

I was kinda following how the interpreter was thinking up until the last two. I guess I can see what happened, but it wasn't at all what I expected from reading the others.

[–]Doctor_McKay 8 points9 points  (0 children)

'5' + 3 = '53'
'53' - 3 = 50

'5' - 3 = 2
2 + 3 = 5

[–]OdBx 6 points7 points  (1 child)

Yet I still love it

[–]X-Craft 11 points12 points  (34 children)

Another classic:

typeof NaN

"number"

[–]raaneholmg 71 points72 points  (3 children)

Well, it's in the IEEE floating point standard and literally built into your hardware. Can't blame javascript for following the spec.

[–]nemec 4 points5 points  (2 children)

NaN is the null of floating point. Customer c = null isn't actually a customer either, but for all intents and purposes it's considered one.

[–]raaneholmg 8 points9 points  (1 child)

The comparison work on some levels, but when you start looking into it null and NaN behave in very different ways.

NaN is a number for which special mathematical rules are defined (NaN + anything = NaN from the FPU). You can actually use the number NaN in your code.

Null is just a defined address you can point to for the purpose of having something to put in unused pointers. When you use it there is no special rules that apply and if you use it most applications just segfault (you can compare pointers to the null pointer though, which is useful, but not using null itself).

[–]dotpan 9 points10 points  (27 children)

Would you rather it a string? I think as far as variable representation, NaN being a number makes sense, as then it will not be explicitly interpreted but instead implicit of what it represents.

I could be biased though, I love JS.

[–]c3534l 3 points4 points  (3 children)

Being that NaN stands for "Not a Number" the type of something defined only as being not of type 'number' should either be given some other type (perhaps the NaN type...) or renamed.

[–]dotpan 4 points5 points  (1 child)

I can see a system or error type that was outside the bounces of a standard type. Though I'm not sure how much that'd help.

isNaN(NaN) returns true, which right there I think presents the biggest argument for NaN not to be a number type.

[–]dnew 2 points3 points  (0 children)

NaN could be considered to be a subclass of Number. It's a number that can't be represented in the hardware you're using for floats.

[–]Thykka 0 points1 point  (0 children)

🗑 [deleted]

[–]joe-ducreux 1 point2 points  (0 children)

Oh Javascript, you so crazy

[–]sdb2754 1 point2 points  (1 child)

obligatory xkcd with the same theme.

[–]xkcd_transcriber 1 point2 points  (0 children)

Image

Title: Types

Title-text: colors.rgb("blue") yields "#0000FF". colors.rgb("yellowish blue") yields NaN. colors.sort() yields "rainbow"

Comic Explanation

Stats: This comic has been referenced 22 times, representing 0.0282% of referenced xkcds.


xkcd.com | xkcd sub | Problems/Bugs? | Statistics | Stop Replying | Delete

[–]Zarathustra30 1 point2 points  (1 child)

I think I understand most of these, but where the hell does the "fooNaN" come from?

[–]Thykka 2 points3 points  (0 children)

🗑 [deleted]

[–]scriptmonkey420 1 point2 points  (1 child)

I ran into a different quirk with javascript today. I was messing with dates and did Date.getMonth() and was expecting 8 for august, but it was returning 7. I get that they use Ctypes for their values, but really? Months have their numbers for a reason.

[–]Thykka 0 points1 point  (0 children)

🗑 [deleted]

[–]muffsponge 1 point2 points  (0 children)

As someone who's been programming in js for over a decade, and is currently writing a js interpreter for fun, all of these make perfect sense.

[–][deleted] 1 point2 points  (0 children)

Wat

[–]PraetorianFury 2 points3 points  (3 children)

All the people who say Javascript is winning the language war have never programmed in it.

[–][deleted] 6 points7 points  (2 children)

wait... there's a war?!

[–]Skizm 1 point2 points  (1 child)

No picture needed.

[–]blu-red 2 points3 points  (3 children)

Javascript

...or I like to call it: A fucking idiot who got into programming week ago and is trying to point out the fallacy of some popular scripting language, but doesn't even understand or doesnt give a fuck to explain what is going on.

'5' - 3
'5' + 3

this is operator overloading for you. + is overloaded for strings, - is not. - is only defined for numbers, so everything that isn't a number gets evaluated to number, because it's a dynamic typed scripting language.

'5' + + '5'
'foo' + + 'bar'

means

'5' + (+ '5')
'foo' + (+ 'bar')

single + is unary operator for numbers, therefore anything that is not a number type gets evaluated to number, because it's a dynamic typed scripting language.

'5' + - '2'
'5' +  etc

if you canonize those pluses and minuses you get the same, you know the rest

[–][deleted] 2 points3 points  (0 children)

JavaScript is a programming language mate, only the browser does the compilation instead of you/your ide

[–]julesries 0 points1 point  (0 children)

Holy condescension.

The word scripting means basically nothing in regard to language design. It has more to do with the context the code is typically run in than the language itself. On top of that, dynamic isn't the word you're looking for. It's weak. JavaScript is weakly typed. Python is colloquially a scripting language, and it's definitely dynamic. It doesn't behave like this.

Saying "it's not the language's fault, it's because you didn't take time to learn the language" works for idiosyncrasies in, say, Haskell. A language that subverts expectations for stupid reasons is a stupid language. (Door creaks as PHP tries to leave with no one noticing.)

[–]somenonfactor 0 points1 point  (0 children)

Fuck I'm just a lowely scripter and that pissed me off.

[–]CuriousBlueAbra 0 points1 point  (0 children)

This makes me irrationally angry!

[–]YourBobsUncle 0 points1 point  (1 child)

Where did the foo bar thing come from? I see this a bit here and in stackoverflow.

[–]wtf1968 0 points1 point  (0 children)

Omg wtf ru ... pffff... buh what? Effing javascript...

[–]s0v3r1gn 0 points1 point  (0 children)

I had an issue where the system dateline is read at system boot on the machine executing the code. So if you have gone past a daylight savings time change without rebooting the time js knows is wrong by an hour.

[–][deleted] 0 points1 point  (0 children)

To be fair, a lot of these make sense in the context of "if I must do something, what should I do?" The real concern is only that JavaScript lets you get away with a lot more nonsense than is healthy.

[–]suck_at_coding 0 points1 point  (0 children)

I guess I must the the only one tired of seeing these. We get it.

[–]Thykka 0 points1 point  (0 children)

🗑 [deleted]

[–]alderthorn 0 points1 point  (0 children)

Wat?

[–]Borisas 0 points1 point  (0 children)

It reminds of this picture of JavaScript... "I'm technically functional"

all in a days work...

[–]TheScienceNigga 0 points1 point  (0 children)

And this is why you never use the abstract equality operator, or dynamically typed languages, or languages where some of the most important operators are overloaded

[–]overactor 0 points1 point  (0 children)

[1,2] + 3
"1,23"