For example, if we save a setInterval()
to a variable, does it already run automatically even though that variable has not been called anywhere?
Example:
let i = 0;
let myInterval = setInterval(function(){
console.log(i++)
if(i > 10){
clearInterval(myInterval)
}
},1000)
I did not even call myInterval
nowhere and it is already running ...
Are variables already automatically executed when declared?
The question is only because in the function we have to call it somewhere, do you understand?
Is this true for JS or for all languages?