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

196
Views
Javascript setTimeout está devolviendo el valor de mi parámetro de función como indefinido

Por favor, consulte mi siguiente código:

 //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>

Cuando uso la función setTimeout ,

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

la salida de name se vuelve undefined .

Por favor, ayúdame con la sintaxis correcta.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Cuando escribe setTimeout(param1, param2) está ejecutando la función debido al paréntesis.

 //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!