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

233
Views
returning the higher value in logical operators in javascript

I am practising the logical operators in JavaScript and fully understood the concepts, but It seems that I didn't with this equation.

    const one = 1;
    const two = 5;
    console.log(one && two);

Why in this case it returns five and not one, shouldn't be returned the first value since both are true ?

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

0

From MDN on the && operator:

"If expr1 can be converted to true, returns expr2; else, returns expr1."

So in this case, 1 can be converted to true, so it returns the second value, 5.

about 4 years ago · Juan Pablo Isaza Report

0

The LOGICAL && operator returns the last value if all other values are true, or else it will return the first non truthy value.

i.e. Java != JavaScript

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!