I am assigning a variable, a function using setInterval, but I do not want the function to execute until I call it. However, the function is performed only from the assignment statement.
sessionClock = setInterval(function() {
console.log("Hi")
}, 1000)
I also tried like this:
sayHi = function() {
console.log("Hi");
}
var sayHiStarter = setInterval(sayHi, 1000);
Both of them initiate the function and will record "Hi" to the console.
Why does he work on appointment? And what can I fix it?
source
share