0

When I run the code below, I get the following output: 'hi', 'text', true. However, I want the output: 1, 'hi', true. Is this possible without some kind of workaround and without manually assigning the first argument?

function myFunc(number=1, text='text', bool=true) {
  console.log(number, text, bool)
}
myFunc(text='hi')
  • 1
    JS does not have "named parameters", they're all positional, although you can make the function accept an object instead. – Bergi Apr 30 '21 at 17:23
  • 1
    To get the default value for the first argument, pass `undefined`, as in `myFunc(undefined, 'hi');` – Bergi Apr 30 '21 at 17:24

0 Answers0