I suddenly feel so confused about this example:
https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_win_setinterval_clearinterval
in the script,
var myVar = setInterval(myTimer, 1000);
function myTimer() {
var d = new Date();
var t = d.toLocaleTimeString();
document.getElementById("demo").innerHTML = t;
}
function myStopFunction() {
clearInterval(myVar);
}
for the
var myVar = setInterval(myTimer, 1000);
Why this setInterval(myTimer,1000) function is executed when we are assigning this whole function to the variable myVar? So if we just use setInterval(myTimer, 1000);, it will be executed, but if we use var myVar = setInterval(myTimer, 1000);, it will be both executed and assigned to the variable myVar at the same time right? May I know what is logic behind it? What is this myVar after this assigning? What is the inner logic that we use clearInterval to this myVar to stop? Thank you so much!