How to create javascript delay function [duplicate]
问题 This question already has answers here : What is the JavaScript version of sleep()? (75 answers) Closed 5 years ago . I have a javascript file, and in several places I want to add a small delay, so the script would reach that point, wait 3 seconds, and then continue with the rest of the code. The best way that I thought of doing this was to create a function, which I could call from anywhere in the script. function startDelay(lengthOfDelay) { //code to make it delay for lengthOfDelay amount