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

200
Views
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 answers
Answer question

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 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!