setTimeout(function, waitTime)
when you pass a function to the setTimeout
method, the method waits for a specified amount of time waitTime
, and it calls the function function
.
But passing in console.log('hello')
only simply logs out "hello"
, but does not return anything and thus does not actually pass a function or callable into the method.
Many ways to go around this:
setTimeout(function(){console.log("hello");},1000); //passes an actual function
setTimeout(()=>{console.log("hello");},1000); //lambda, passes an actual function
setTimeout(()=>console.log("hello"),1000); //same here
Also, if it was supposed to be repeated over intervals, then use setInterval
(same arguments as setTimeout
).