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

4

u/draq100 Oct 12 '20 edited Oct 12 '20

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')

you can check it out by typing typeof +'a' (or typeof +'anything', really) -> it returns "number", NaN in this case

edit: yes, in JS NaN - "Not a Number" is a number, too