This is really basic javascript here and probably pretty silly to ask but what is the difference between:
a) function variable(){}; b) var variable = function() {};
I think the second one executes as soon as the browser reads it, am I correct?
This is really basic javascript here and probably pretty silly to ask but what is the difference between:
a) function variable(){}; b) var variable = function() {};
I think the second one executes as soon as the browser reads it, am I correct?
Your first example is a function statement. The second is a function expression. Per MDN:
The main difference between a function expression and a function statement is the function name, which can be omitted in function expressions to create anonymous functions. A function expression can be used as a IIFE (Immediately Invoked Function Expression) which runs as soon as it is defined. See also the chapter about functions for more information.