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

230
Views
Advantage of inline boolean conditional vs explicit if statement?

Recently I came across this little bit of JS logic:

close(focusAfter) {
    if (! this.open) return;

    this.open = false;

    focusAfter && focusAfter.focus();
},

The truthy-ness check of focusAfter is clearly used as an inline conditional to make sure a valid object/element exists before calling .focus() on it.

It seems to me that the equivalent logic could be clarified when rewritten as:

if (focusAfter) focusAfter.focus();

My question is: is there any "not-immediately-obvious" advantage to the inline boolean-check-then-execution shown in the original example versus explicitly writing an inline if statement to "wrap" the executed logic (in this case, focusAfter.focus())?

about 4 years ago · Juan Pablo Isaza
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!