Anonymous functions

Hello Everyone,

While writing the last blog i came across a term Anonymous functions.It intrigued me so i did some learning & here comes the Blog.

What is Anonymous functions ?

“An anonymous function is a function without a name.”

Anonymous functions are declared using the function operator instead of the function declaration. You can use the function operator to create a new function wherever it’s valid to put an expression. For example you could declare a new function as a parameter to a function call or to assign a property of another object.

var bob = function(){



Debugging: we see the name of functions in the stack trace. If all we’re seeing is “anonymous” up and down the stack, that’s not too useful.

Recursion: a function can call itself when it has a name. If it’s only assigned to a variable, then that variable is outside the function’s scope.


Scope: when creating a fake “block” scope using an immediately executing function, we don’t really need a name.

Execution : if it’s a very short function or callback, or an immediately-executing function, it’s nice to keep the function declaration short by omitting a name.

Resources : Scott Logic