When to use anonymous JavaScript functions?
Answers
Answered by
5
Hi
What is anonymous JavaScript function?
As name suggests.. a function which doesn't have identity, in JavaScript we identify a function with it's name. So.. a function which doesn't have name is called an anonymous function.
When should we anonymous function?
We should use anonymous function only when if we know that we do not need reference of this function in future.
for e.g. we can use anonymous function to create fake namespace in JavaScript or we can also pass them as argument for click events.
syntax:
function(arg1, arg2...) {
// do something here
}
Similar questions