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

187
Views
How to redeclare function parameter if it is not actually passed into function?

What is the best way to redeclare a function parameter if it is not actually passed into the function?

function testVariable(foo, bar) {
    bar = bar ? bar : foo; // <--
    return bar;
};

const myFinalValue = testVariable("testValue");

I want to do this to ensure that bar has a value before I continue my automation (return, in this example).

Do I have to declare a new variable name or is it possible to overwrite the given parameter?

If I overwrite that parameter, will the overwritten variable become global if no value has been passed for that parameter into the function (per the example)?

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

0

Just use defaults, and then check if the variable is the default, if it is then do whatever you want

function testVariable(foo, bar = foo) {
    return bar;
};

const myFinalValue = testVariable("testValue");
console.log(myFinalValue);

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!