Today I was trying random letters printing using nodejs, Somehow I tried to print ‘banana’ in log but unfortunately I miss n (letter) to log but still it works fine. Why does it prints whole banana instead of ‘baaa’?
('b' + 'a' + + 'a' + 'a').toLowerCase();
The output is banana but why? Even if + + (empty char) generates NaN then still it should print bananaa not just banana.
Screenshot:
>Solution :
The extra + acts as a unary operator on the following ‘a’, and tries to coerce it to a number, resulting in NaN. The remaining + symbols are all interpreted as string concatenation which causes NaN to be coerced to string ie. ('b' + 'a' + + 'a' + 'a') = ('b' + 'a' + NaN + 'a') = ('baNaNa').
