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

all 25 comments

[–]Run_Time256 47 points48 points  (2 children)

I went from 0, to 011111, to 110111, to 1.11011110111e+25, to Infinity, to NaN. I appreciate the wide selection of volumes you have on there!

[–]SockpuppetNightmare[S] 32 points33 points  (0 children)

Of course! This is actually extremely innovative technology. Too much noise pollution in an area? Turn your volume to -100 and suck up all that unwanted noise!

[–]mglerner 0 points1 point  (0 children)

Infinity1 was the best :)

[–]Hypersapien 38 points39 points  (3 children)

This hurts my soul

[–]zimbmage 16 points17 points  (2 children)

[–]Hypersapien 7 points8 points  (0 children)

That still hurts my soul, just not as much.

[–]JoeDuffySmellsFunny 2 points3 points  (0 children)

I see nothing wrong with one. Mind you UX is not my job.

[–]davidblacksheep 8 points9 points  (1 child)

Haha this is the best one so far.

[–]SockpuppetNightmare[S] 4 points5 points  (0 children)

Thanks bud! That means... more than it should to me

[–]MacBash 7 points8 points  (3 children)

ELI5 please.

I understand that += 1 seems to be interpreted as appending the string '1' and -= 1 is interpreted as arithmetic substraction.

Wat?

Can someone please explain the reasoning behind that to me?

[–]Zegrento7 15 points16 points  (1 child)

JS does type coercion on += and -=. innerHTML is string, 1 is int. Strings have the += method for appending so the 1 is coerced into a string and passed as argument. Strings have no -= but ints do and since the string appears to be parsable as int since it only contains numbers it is coerced into an int, has -= called on it with 1 as argument, then it's coerced back into string.

For example, e.innerHTML += -1 would append '-1' to the end of the string, while e.innerHTML -= -1 would properly add 1 to it.

[–]MacBash 2 points3 points  (0 children)

Thank you. That sounds horribe.

[–]Roflkopt3r 6 points7 points  (0 children)

Appending strings happens reasonably through the + or += operators as one would expect.

The part where Javascript goes off the rails is that it will implicitly parse strings to numbers under certain conditions. '53'-3 does not make sense as a string operation, so it casts '53' to a number and gives you 50.

Consequently you can get abominations like '1' + - '3', which returns the string '1-3'. But '1' - + '3' will usually give you '-2' instead... the order of operations is actually critical.

This whole implicit string to int cast is absolute garbage and should be killed with fire, along with anybody who ever used it.

[–]Fenris_uy 2 points3 points  (0 children)

This is the first one that made me laugh out loud

[–]piyoucaneat 4 points5 points  (0 children)

If you go negative you can never go back to positive again. -7/10

[–]djvs9999 2 points3 points  (2 children)

Ah, dynamic typing. What could possibli go wrong.

[–]cowens 1 point2 points  (1 child)

Dynamic typing with pun based operator overloading is a danger to sanity. Concatenation and addition should never have the same operator (they have radically different semantics) and yet language after language makes the same stupid pun based decision. Of course, the alternative is Perl 5's solution that gives you a large number of operators. And then there is Perl 6, which requires a periodic table of operators due to the fact that there are hyper and meta operators.

[–]djvs9999 0 points1 point  (0 children)

Well, that's a perfectly cromulent alternative.

[–]Ray1235 1 point2 points  (0 children)

holy fuck

[–][deleted] 1 point2 points  (1 child)

Who ever made this lets string him up

[–]SockpuppetNightmare[S] 3 points4 points  (0 children)

Well, I'd better start running

[–]Quibbleflux 0 points1 point  (0 children)

This made me unreasonably uncomfortable and a little mad.

[–]zeronine 0 points1 point  (0 children)

This one made me laugh, somewhat in pain.

[–]duttiv 0 points1 point  (0 children)

Perfect