Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda