Apr
1
2013

Anonymous functions in JavaScript

The functions that are dynamically declared at runtime are called anonymous functions. They are not given name in same way as normal functions. Anonymous functions are declared by function operator. We can use the function operator to create new function.

A reference to the function that was created will be returned by function operator, and then function can be assigned to a variable, passed as parameter or returned from another function. It is possible because functions are first class objects in javascript.

Following is the example where a function is declared in normal way.

Function showvalue(){
    Alert(“it is value”);
} 
Showvalue();

Following is the example where the same function is declared dynamically using function operator.

Var showval;
showval = function(){
   Alert(“it is value”);
};
showval();

About the Author: Web Source Blog

Software Developer

Pinterest
Email
Print