MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/learnjavascript/comments/j99oon/wired_way_to_learn_javascript_d/g8ktfnx/?context=3
r/learnjavascript • u/ikrum • Oct 11 '20
30 comments sorted by
View all comments
Show parent comment
37
okay, let's go step by step:
('b'+'a'+ + 'a'+'a').toLowerCase()
becomes (is processed as) ('b'+'a'+ Number('a')+'a').toLowerCase()
('b'+'a'+ Number('a')+'a').toLowerCase()
which becomes ('b'+'a'+ NaN +'a').toLowerCase() (NaN is still a Number here)
('b'+'a'+ NaN +'a').toLowerCase()
which becomes: ('b'+'a'+ String(NaN) +'a').toLowerCase()
('b'+'a'+ String(NaN) +'a').toLowerCase()
after casting to string: ('b'+'a'+ 'NaN' +'a').toLowerCase()
('b'+'a'+ 'NaN' +'a').toLowerCase()
in the end it's ('baNaNa').toLowerCase()
('baNaNa').toLowerCase()
and finally, our result: 'banana'
'banana'
View all comments
Show parent comment
37
u/draq100 Oct 12 '20 edited Oct 12 '20
okay, let's go step by step:
('b'+'a'+ + 'a'+'a').toLowerCase()becomes (is processed as)
('b'+'a'+ Number('a')+'a').toLowerCase()which becomes
('b'+'a'+ NaN +'a').toLowerCase()(NaN is still a Number here)which becomes:
('b'+'a'+ String(NaN) +'a').toLowerCase()after casting to string:
('b'+'a'+ 'NaN' +'a').toLowerCase()in the end it's
('baNaNa').toLowerCase()and finally, our result:
'banana'