View Full Version : Why Doesn't it Work?

08-11-2007, 12:43 AM
Why doesn't:

function () {alert("Test");} ();
Are you supposed to put a name

function !!!HERE!!! () {alert("Test");} ();
As if you were doing:

function test (stringie) {alert (stringie);}
I'm just wondering because sometimes if I want to localize variables I try and use that.

08-11-2007, 01:15 AM
(function(){alert("Test");})(); //this will work

or as you write it with the whitespace:

(function () {alert("Test");}) ();


If you're any interested, I've written a little tutorial on Javascript at:

It'll cover anonymous functions.

08-11-2007, 01:26 AM
Thanks, but was I correct on why?

08-11-2007, 01:32 AM
I don't know why it doesn't work without the extra set of parenthesis. Perhaps it's just a matter of syntax rules :D