An anonymous function allows a programmer to create a function that has no name . In other words anonymous functions can be used to store a bit of functionality in a variable and pass that piece of functionality around it and created at runtime. Anonymous functions are declared using the function operator instead of the function declaration.
Normal function definition:
In the above script you can see, it creates a function with name "callMe".
Anonymous function definition:
In the above script you can see, it declares an unnamed function and assigns it to a new variable named "callMe".
Here, we can see that these two ways of defining a function are essentially the same; both result in a function being created, and a new variable named "callMe" assigned to the current scope. However, the second function is anonymous. The function operator can be used anywhere that it's valid to use an expression. For example you can use the function operator when a variable is being assigned, when a parameter is being passed to a function or in a return statement.
- What is noscript tag?
- Difference between '=', '==' and '===' operators?
- What is Browser Object Model
- How to test a string as a literal and as an object ?
- What is Associative Array? How do we use it?
- What's the Difference Between Class and Prototypal Inheritance?
- Event bubbling and Event Capturing in JavScript?