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

74
Views
JavaScript AND / OR Operand

The priority of AND && is higher than OR ||. That's why it works before OR.

In the example below, 1 && 0 is calculated first.

alert( 5 || 1 && 0 ); // 5

I don't understand how this happens?

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

0

The left-hand side will be evaluated first. Please see example

a || (b * c);  // evaluate `a` first, then produce `a` if `a` is "truthy"
a && (b < c);  // evaluate `a` first, then produce `a` if `a` is "falsy"
a ?? (b || c); // evaluate `a` first, then produce `a` if `a` is not `null` and not `undefined`
a?.b.c;        // evaluate `a` first, then produce `undefined` if `a` is `null` or `undefined`

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence

about 4 years ago · Juan Pablo Isaza Report

0

Please check Operator Precedence for more details.

Order is from left to right, when any of the early left part evaluates to be true, the rest of right side is not evaluated and is omitted.

console.log(5 || false); // 5
console.log(true || 5 || false); // true
console.log(false || 5 || 10); // 5
console.log(false || 10 || 5); // 10

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!