Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a "use default parameter" argument syntax for functions?

If I have a function declared with two default parameters, like this:

const doSomething = (defaultVal = 'me default', useThis = false) => {
      /* ... */
};

And I want to call the function passing in an argument for the second parameter, but have the first argument just use the default value:

doSomething(???, true);

Is there some syntax for telling the function to use the default parameter, or does a real value need to be passed in?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Pass in undefined

const doSomething = (defaultVal = 'me default', useThis = false) => {
  console.log({ defaultVal, useThis });
};

doSomething(undefined, true)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading