3 ms·
Prepending a ! results in the parser picking up the line as a expression instead of a statement. function foo(){}; // statement var a = function() {};
by BonsaiDen 12y ago
Prepending a ! results in the parser picking up the line as a expression instead of a statement.
function foo(){}; // statement
var a = function() {}; // the right side of the = is a expression, a function keyword inside a expression does also not require a name
Also function statements are put into the scope before execution of the program begins, expressions on the other hand need to be evaluated.
So this will work:
foo();
function foo(){}
While this will throw the usual `Undefined is not a function` (it does not throw foo is not defined, because the var statement gets hoisted, meaning before the code is run the compiler will move all var statements to the top of the nearest scope (i.e. function)
foo();
var foo = function(){};
Now, as for why he closed the tab, first of all it is pretty clear that this is a very dumbed down explanation of the whole thing, and while there is a SO link it's not immediately clear that all operator tokens can trigger this behavior.