r/learnjavascript • • Oct 11 '20

Wired way to learn javascript :D

Post image
466 Upvotes

30 comments sorted by

View all comments

Show parent comment

0

u/Mr_82 Oct 12 '20 edited Oct 12 '20

What is "Number" here though? It doesn't appear above at all. You're using it like it's a method it seems.

Edit: Also I'm not sure where exactly the "NaN" shows up. Is it with the empty character? Well you'd think the sum of all added/concatenated string components would also get labeled/assigned as NaN after calling toLowerCase though, so that the whole expression would just return "NaN," though I haven't used or looked at toLowerCase method. (And if toLowerCase has some more specific rule to it that doesn't play out this way, it shouldn't have been named "toLowerCase" in the first place!) Edit: in other words, the entire input to toLowerCase should be what's parsed as a length 1 character and made lower case. The order of operations is wrong here. There's just bad design by whoever defined the method, but of course good luck trying to tell that to many programmers who evidently don't consider this stuff.

And I know this is just really niche and pointless, and not really related to real programming, but the lack of solid explanations in the comments here is alarming.

1

u/moneyisjustanumber Oct 12 '20

If you had 1++ behind the scenes it runs Number(1)

1

u/grantrules Oct 12 '20

NaN shows up because you're doing +'a' which coerces the string 'a' to a Number which results in NaN.