What does () mean in JavaScript -
i'm testing invoked function in javascript. found when running below code in chrome, throws uncaught syntaxerror: unexpected token )
function foo(){ console.log(1); }();
i think parser break code 2 parts: function declaration , ();
. happen if add 1
between ()
, turns out won't throw error.
so suppose (1);
valid expression, means?
thanks answer.
it immediately-invoked function expression:
(function foo(){ console.log(1); })(); // call function here
explanation:
suppose create function:
function foo(){ console.log(1); }
now call function do:
foo()
now if saw gave function name , called it. can call in same line like:
(function foo(){ console.log(1); })();
here article can read.
Comments
Post a Comment