Anonymous function in JavaScript is a function which doesn’t have any name.Normally you declare a function in JavaScript using function declaration as:
function SomeFunction(){ }
Here SomeFunction is the name of the function.It is called declared function.
Anonymous functions are commonly used in function expressions.In the following example of function expression you declare function as a part of expression.It is declared using the following syntax:
var identifier=function FunctionName[option](){ }
Anonymous function
In this function expression you can specify the function name or not as it is optional.If you don’t specify the function name then it is called anonymous function.
var func=function() { alert('test fun'); } func();
you declare anonymous function using the function operator instead of using function name.You use the variable name to invoke the function.
Leave a Reply