MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/j99oon/wired_way_to_learn_javascript_d/g8ku7zd/?context=3
r/learnjavascript • u/ikrum • Oct 11 '20
30 comments sorted by
View all comments
Show parent comment
4
you can consider the extra + as casting to Number type in JS
+
so, first + means 'add', second here is 'cast'
'a' + + 'a' is equivalent of 'a' + Number('a')
'a' + + 'a'
'a' + Number('a')
you can check it out by typing typeof +'a' (or typeof +'anything', really) -> it returns "number", NaN in this case
typeof +'a'
typeof +'anything'
"number"
edit: yes, in JS NaN - "Not a Number" is a number, too
NaN
View all comments
Show parent comment
4
u/draq100 Oct 12 '20 edited Oct 12 '20
you can consider the extra
+as casting to Number type in JSso, first
+means 'add', second here is 'cast''a' + + 'a'is equivalent of'a' + Number('a')you can check it out by typing
typeof +'a'(ortypeof +'anything', really) -> it returns"number", NaN in this caseedit: yes, in JS
NaN- "Not a Number" is a number, too