That promise should resolve after ms milliseconds, so that we can add .then to it, like this: function delay(ms) { // your code } delay(3000).then(() => alert('runs after 3 seconds')); along with a different example and its code implementation. Our debounce function does both.The most common use function func1() { Search box suggestions, text-field auto-saves, and eliminating double-button clicks are all use cases for debounce. However, you can only call this custom wait() function from within async functions, and you need to use the await keyword with it. I have two javascript functions that are called from android. JavaScript wait() To make JavaScript wait, use the combination of Promises, async/await, and setTimeout() function through which you can write the wait() function that will work as you would expect it should. The two key methods to use with JavaScript are: setTimeout ( function, milliseconds) Executes a function, after waiting a specified number of milliseconds. Note, many browsers have a minimum delay length of between 25 and 75 ms, with some of the fastest browsers having a minimum delay of about 3 ms. setTimeout(function(){ v.close() }, 2000); On clicking the button, a message gets displayed as shown below. Here, two buttons are present. The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds.