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

209
Visualizações
Javascript var and function hoisting discrepancy

function test1(a = 1) {
  console.log(a);
  var a = 2;
  function a() {}
}
function test2(a = 1) {
  console.log(a);
  function a() {}
}
test1(); // console log  1
test2(); // console log  [Function: a]

According to the understanding of variable hoisting, the variable a in the first function has the same name as the function a, and finally the function a covers the variable a, and there is only the function a in the second function. The output result should be the same.So Why is the function default parameter valid in the test1 function but not in the test2 function?

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