They are identical for the goals you are talking about.
The only difference is that inside the second function you have a clean reference to the function from the inside.
Formally
The language specification states:
Function expression:
Function Identifier (opt) (FormalParameterListopt) {FunctionBody}
The identifier (in this case, Person ) in the function expression is optional
The rationale for this is explained a bit later in the language specification:
NOTE An identifier in a Function expression can be referenced from within a FunctionExpression FunctionBody function to call a function recursively. However, unlike FunctionDeclaration, the Identifier in the Function expression cannot reference and does not affect the scope of Expression.
On practice
You can use the second option in two situations:
When this makes your code clearer:
(function removeBodyDivs(){
It may be clearer than:
(function (){
When doing recursion, for example
var f = function fib(n){ return n<2?2:(fib(n-1)+fib(n-2)); }
source share