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

133
Views
Facing Problem With Optional Parameter in Javascript

In Javascript I defined a function with one require parameter and some optional parameters. But when I want to call the function with only some optional parameter, then I am facing the problem.

function foo(par1, par2='default_value1', par3='default_value2', par4='default_value3'){
   //do the stuff
}

It works-

foo('some_value');
foo('some_value', par1='some_value');
foo('some_value', par1='some_value', par2='some_value');

But it's not works-

foo('some_value', par1='some_value', par4='some_value');

In this case, value of "par4" automatically assigned to "par3" during the execution of the function. I.e. value of par3 will be "some_value"

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!