Why not use parentheses?


#1

I've finished the JavaScript and jQuery tutorials, and whenever we called a function, we would enter the name of the function, and then we would enter parentheses like this:

var example = function(){
    return "example";
};

example();

But in the lesson, we don't use the parentheses:

var main = function(){

};

$(document).ready(main);

Why?


#2

Hi Frogman37,

Since it's expecting a function as an input in your second example, the parenthesis aren't necessary. If you want to pass parameters along, you still could though, for example:

function double(num) {
  return num * 2;
}

$(document).ready(double(9374));

I'm sure other people can explain the whole thing for more in-depth, but I hope this helps :)

By the way, what's a frogman?


#3

Okay; thank you for the answer!

To answer your question, just read my bio. :)


#4

Yeah, that took you 5 whole hours. When I posted that, I thought you said you "promptly respond"

I'm just kidding :D.


#5

Well I'm not always on the computer. :)