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

140
Views
Do these two snippets return the same value?

I'm not sure how to title this question, but it's concerning a pattern where the || operator is used to resolve a sequence of undefined values to the first defined one.

Are these equivalent?

export function getRuntime(): Runtime {
  return runtime || findWindow() || mockWindow;
}

and

export function getRuntime(): Runtime {
  if (runtime) return runtime;
  if (findWindow()) return findWindow();
  return mockWindow;
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Both of the code snippets do the same thing, as the || and return is simply doing the same thing as returning from the if statements.

The only difference between the two is that if findWindow() returns a value which is considered true in JavaScript, it will run twice. This "issue" only occurs in the second one.

about 4 years ago · Juan Pablo Isaza Report

0

Yes, both functions do the same thing.

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!