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

193
Visualizações
Javascript setTimeout is returning my function parameter value as undefined

Please refer to my below code:

//Principal Function
function greet3(name, sayName) {
  document.getElementById("jac3").innerHTML = "Hello " + name;
  sayName(name);
};
//Callback Function

function sayName(name) {
  document.getElementById("jac3").innerHTML += ". How are you? " + name;
}
//Calling the function after 10 seconds

greet3("Neha", setTimeout(sayName,3000));
//greet3("Neha", sayName);
<p id="jac3"></p>

When I use setTimeout function,

greet3("Neha", setTimeout(sayName,3000));

the output of name gets undefined.

Please help me with correct syntax.

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

0

When you write setTimeout(param1, param2) you are executing the function due to the parenthesis.

//Principal Function
function greet3(name, callback, timeout) {
  document.getElementById("jac3").innerHTML = "Hello " + name;
  setTimeout(() => callback(name), timeout);
};

//Callback Function
function sayName(name) {
  document.getElementById("jac3").innerHTML += ". How are you? " + name;
}

//Calling the function after 3 seconds
greet3("Neha", sayName, 3000);
<p id="jac3"></p>

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