+ 3
Why these brackets?
Without the last pair of brackets the log won't show. Why? var getReady = function() { log('Ready for action'); }();
10 Answers
+ 5
Because you use an anonyme function...
When you declare a function, you write:
function functionName() {
/* code of your function */
}
This is the same, in fact, that:
functionName = function() {
/* code */
}
Which assign the function to the variable "functionName"...
Well, to call it, in the two case ( because we keep the same name ), you do:
functionName();
So, in your code, you assign at the variable getReady, the value returned by execution of a function without name: you declare it, and execute it once, just after have declared it ( and there is no more way to call it a second time in this case -- sometimes, you declare anonymized function, without explicit assignment to a variable, but you register it even, like if passing to a function, which provide an implicit assignement to the attribute who's a function variable )
+ 4
About the not-question of the log() function: nothing indicates that it's not a custom function, making go know what ^^
+ 3
if you leave the last brackets it will just declare a function if you put last brackets too it calls the function itself
+ 3
@Seiss K said "brackets" but context shows implicitly it was meaning "parenthesis" ;)
+ 1
if u don't place brackets it stores tha function in that variable
ex: var m1 = function(){----};// function stored as an object in m1
m1();// this executes above function
if u place the brackets it executes the function and store the output value of that function
ex: var m1 = function(a,b) { return a+b;}(2,3);
alert(m1);// output is 5 here
here we are creating anonymous function with param's and passing 2,3 as parameters. that function return value stored in m1.
0
I am not sure but maybe you should type 'console.log' instead of just 'log'.
I have absolutly no idea what the last parenthesis are about
0
Thats it. Console.log() not lo()
0
now, that's a good answer! Thumbs up for visph!
0
the brackets r used for declaring a block of code
0
Because you need to "call" function execution. Eather with some parameter inside brackets or empty brackets if you don't have parameter...



