How to make a delay before running a function in JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to make a delay before running a function in JavaScript

Pls answer

8th Feb 2021, 8:50 AM
Václav Hajšman
Václav Hajšman - avatar
3 Answers
+ 4
setTimeout(func, 3000); func will be called a bit later than 3 seconds (3000 milliseconds). Notice that I did not put parantheses: func not func()
8th Feb 2021, 8:59 AM
Ore
Ore - avatar
+ 3
Use 'setTimeout(function, delay)' function. Example (sorry if too complicated): https://code.sololearn.com/WijhEK1U6Bpb/?ref=app (this "no connection" bug...)
8th Feb 2021, 9:03 AM
#0009e7 [get]
#0009e7 [get] - avatar
+ 1
Ore Thank you, it works!
8th Feb 2021, 9:03 AM
Václav Hajšman
Václav Hajšman - avatar