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?

>Solution :

Pass in undefined

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

doSomething(undefined, true)

Leave a Reply