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

172
Visualizações
Mismatched parameters

I understand the case when a function may have less arguments than the function signature allows, such as:

function sum(x, y=1) { return x+y; }
console.log(sum(5));

Or more parameters if its a vargs/rest function:

function sum(...rest) {
    let s = 0;
    for (let n of rest) s += n;
    return s;
}
console.log(sum(1,2,3,4,5));

But why does the following not raise an error?

'use strict';
function addEmUp() {
    let sum = 0;
    for (let arg of arguments) sum += arg;
    return sum;
}
console.log(addEmUp(1,2,3,4,5));

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The default values for parameters and the rest parameters are a relatively new functionality of JavaScript, they were introduced in ES2015. Before that, the only way to have a function with any number of arguments was by using the arguments object. It has been available since the first versions of JavaScript.

No matter how a function accesses its actual parameters, it can be called with less or more parameters than its declaration requires. When there are less actual values than declared parameters on the call, the remaining parameters are not initialized (their value is undefined), when the function is called with more values than it is declared, the extra values can be accessed only by using the arguments object (or with the rest syntax).

about 4 years ago · Juan Pablo Isaza Relatório
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