You are calling the function in the first parameter of setTimeout
. It is supposed to be a callback function(function definition). Just copy the code of the main function inside the setTimeout
function and it will work.
The setTimeout
Function is used usually with two parameters.
- The callback function
- Time in milliseconds
The callback function is called after a given time (second param).
This is how it is called:
const callbackFunction = () =>{
console.log("Inside callback");
}
setTimeout(callbackFunction, 2000);
OR simply
setTimeout(() =>{
console.log("Inside callback");
}, 2000);
Output (after 2 secs)
Inside callback