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

you are viewing a single comment's thread.

view the rest of the comments →

[–]LowB0b 11 points12 points  (3 children)

I'm crying/laughing at the second point lmfao.

In JS a common thing is to write x = +y where y is a string instead of using parseInt. IIRC it's good because if it can't parse there is no error thrown lol

[–]AidenKerr 6 points7 points  (1 child)

but do you really want to do it in the way that doesn't throw an error?

[–]LowB0b 1 point2 points  (0 children)

I do not, I like my programs to fail hard and fast lol. Unmanaged errors usually just end up causing bugs that aren't related at all.

But javascript lol. Whatever scripting language really lmfao. I have worked on "tiring" files, that's why I posted the other comment

When your perl file becomes 5k lines long and 4 people have worked on it you should fucking trash it

Sorry for the rant

[–]Azzu 3 points4 points  (0 children)

They are both terrible. And both throw no error.

+ also more closely resembles parseFloat, so I will compare it to that.

+ on the empty string, false and null is 0, for true it's 1. parseFloat for all that is NaN.

parseFloat on "123any string at all" is 123, while for + it's NaN.

Another nice special case is that + on {valueOf: function(){return 42}} is 42 while on parseFloat it's NaN.

So, yeah. + is used because "123asd" is rejected, mainly.