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

86
Views
Is there a better way to handle default value?

There are too many times I have write something reassembling this:

const foo = some_expression ? some_expression : some_default_value;

This is really long already and normally an expression would be even longer. Is there a concise way to do this in JS/TS?

I know I can define a function but this is still not ideal in my opinion.

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

0

const foo = truthy || whatever;

If they are parameters passed into your function you can set a default when passed:

function foo(bar = 'biz') {

}
about 4 years ago · Juan Pablo Isaza Report

0

const foo = some_expression || some_default_value

for more details: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR

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!