-2

Self-calling function is a function that executes automatically when you create it, and has the following form:

(function(){
    // some private code that will be executed automatically
})();  
(function(a,b){
    var result = a+b;
    return result;
})(10,20)

What I am curious about this is why we need this? Thus these functions don't have their own names, developers won't be able to call them anywhere they want which causes poor code reuse.

0 Answers0