Why does declaring var timer = setTimeout(etc.) automatically execute the setTimeout() function? And how would one pass a setTimeout() function as a variable without having the setTimeout() automatically execute?
var do_this = function(params){console.log("executes automatically, but function is only declared")};
var delay = 50;
var timeoutID = setTimeout(do_this(), delay) //executes automatically
Functions such as setTimeout require a callback-function that can be called the moment the timer expires. When you just provide a function, it is called immediately because it is never added to the callback-queue.
Thus, you should pass it a callback-function:
setTimeout( () => ... )