From what I have heard, the following is a “self-calling function”:
func(){}();
How is it different from the following?
func(){} func();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I assume you meant what is the difference between (I):
and (II):
or even (III):
All three behave the same in regard to the results, however they have different naming and scoping consequences:
I: this will not make the function available under any name, it is run once and forgotten. You can not reference it in the future
II:
funcfunction is created and available in the whole enclosing function, even before it is defined (hoisting)III:
funcvariable is defined pointing to a function. It won’t be accessible before being defined.Note that in II and III the function is referencable via
funcname and can be called again multiple times. This is not possible with self-calling function in I.