Possible Duplicates:
What does this JavaScript snippet mean?
Location of parenthesis for auto-executing anonymous JavaScript functions?
(function(){
//something here...
})() <--//This part right here.
What exactly is this )()
?
What if I change it to this ())
?
(function(){
//something here...
}()) <--//Like this
They are the same.
There has to be a parenthesis either around the function definition or around the function call to make it valid Javascript syntax, but it doesn't matter which you use.
To demonstrate what it does, using a named function it would be:
In JavaScript, function definition is a literal - which means, it's an expression with the value of the
Function
object.If you put
()
right after it, you effectively call the function right after defining it.