Anonymous functions can be used as callbacks. Same way we can make anonymous function—calling this function right after it was defined.
Below is an example.
(function() { alert('boo'); } )()
The syntax is simple by adding an anonymous function definition inside parentheses followed by another set of parentheses. The second set basically says "execute now" and also you can put any parameters that your anonymous function might accept.
(function(name) { alert('Hello ' + name + '!'); } )('dude')
The advantage for using self-invoking anonymous functions is to have some work done without creating global variables.