Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

145
Views
Why does Banana is printing in JavaScript?

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:

enter image description here

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report

0

Interesting !!

console.log(('b' + 'a' + + 'a' + 'a').toLowerCase());

console.log(('b' + 'a' + + 'a' + 'a'));

console.log(( 'a' + + 'b' ));

//output
banana
baNaNa
aNaN

In the 3rd statement, the 'b' is not printed as + + 'b' = NaN //not a number and .toLowerCase() makes it nan hence the word banana

about 4 years ago · Juan Pablo Isaza Report

0

Since you are adding nothing with nothing, which is most likely returning NaN

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!