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

88
Views
Why And (&&) operator in if condition returning zero - Javascript

I'm facing a if condition issue in javascript. Please have look on below code.

1.

const a = 1;
if(a && a > -1)
{ 
console.log('suceess')
} 
else
{ 
console.log('failed')
}

Here in if condition it is returning true.

2.

const a = 0;
if(a && a > -1)
{ 
console.log('suceess')
} 
else
{ 
console.log('failed')
}

Here in if condition it is returning Zero.

I'm not getting this. Can someone please explain why is it so.

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

0

in Javascript 0 is considered a "falsy" value, which mean il will be evaluate to false when used in a condition like if (0) {}.

See https://developer.mozilla.org/en-US/docs/Glossary/Falsy for more information about falsy values.

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!