In JavaScript, Why function expression needs to be in bracket for calling the function

56 Views Asked by At

I tried calling

function(v){alert(""+v);}(4);

But warning came out

function statement requires a name


When I called using name

function fname(v){alert(""+v);}(4);

Nothing happened

But when I called using brackets,

(function(v){alert(""+v);})(4);
and
(function fname(v){alert(""+v);})(4);

Both showed alert on screen. Why did this all happened?

0

There are 0 best solutions below