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

210
Vistas
I can't understand the logical operator error in JavaScript

I was coding in node, so I got an error, will you explain this error to me?

When I write a statement console.log(Email||Password||Song)
It's returning the value of Email variable.


But when I write statement console.log(!Email||!Password||!Song);
It's returning actual value which is true/false


Can you Please explain me
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

So, first up the or (||) operator:

a || b === a if a is truthy, otherwise b

So the or operator isn't strictly useful for boolean types. For example, you could set a default value for data like

function makePerson(name, age) {
  return { name: name, age: age || 0 }
}

Next, the not (!) operator:

!a === false if a is truthy, true otherwise

So note that the ! operator strictly provides boolean outputs.

So with your example,

Email||Password||Song

will be Email if truthy, then Password if truthy, and finally Song

!Email||!Password||!Song

is going to end up evaluating to something like

false||false||true

or

true||false||false

etc. By adding in the unary not, you're effectively casting all your inputs to booleans, and the output of the or operator is the type of its inputs.

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