Till now, you have been looking at the setTimeout() method. Now is the time to look closer at this method. You’ll learn from Srishti more about this setTimeout() method in JavaScript.
Syntax of setTimeout() method:
// ES5 Syntax setTimeout(function() { // code to be executed }, timeInMs);
// ES6 Syntax setTimeout(() => { // code to be executed }, timeInMs);
The example code that you looked at is given below:
Code Snippet:
setTimeout(() => { console.log("This is executed after 3 seconds"); }, 3000);
Output: (after 3 seconds)
This is executed after 3 seconds
With Sakshi, you’ll now mock a long-running function using synchronous JavaScript and witness the problems that exist with a long-running function.
In the last video, you looked at what would have happened had the asynchronous behaviour of JavaScript did not exist.