Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

144
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda