Is there a way I can do a sleep in JavaScript before it carries out another action?
Example:
var a = 1+3;
// Sleep 3 seconds before the next action
Here's a very simple way to do it that 'feels' like a synchronous sleep/pause, but is legit js async code.
// Create a simple pause function
const pause = (timeoutMsec) => new Promise(resolve => setTimeout(resolve,timeoutMsec))
async function main () {
console.log('starting');
// Call with await to pause. Note that the main function is declared asyc
await pause(3*1000)
console.log('done');
}