Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!