Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

135
Visualizações
Javascript function with default argument and a multiple-argument

Let's say I have a function declaration like this:

function manyParams(a, b=1, ...n) { ... }

Now clearly I can call this function in such a way that I can provide a, b, and then any number of additional arguments under an array n.

Example:

function manyParams(a, b=1, ...n) {
    console.log(JSON.stringify(a));
    console.log(JSON.stringify(b));
    console.log(n.length);
}

If you call this function with the following arguments manyParams(1, 1, "John", "Stacy", "Mike", "Bob", "carly");, you get this output, which makes sense:

1
1
5

However, what if I want to use the default value in b, while still providing many arguments, how do I specify that "John" is the start of n? I would think I could do something like this: manyParams(a=1, n="John", "Stacy", "Mike", "Bob", "carly"); but that doesn't work. Running those arguments gives me the following output:

1
"John"
4
about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda