Use of Angular.js noop

Angular.js noop is an empty function. You won’t find a detailed explanation even in Angular.js documentation. This function can be used like a placeholder for passing some functions as parameters. An example is given below.


function foo (callback) {

    // Do a lot of complex things

    callback();

}


// Those two have the same effect, but the later is more elegant

foo(function() {});

foo(angular.noop);


The common questions about noop is: rather than just leaving the function blank, what is the benefit of using it?

To us angular.noop is more aesthetically pleasing. This makes no difference than using a new anonymous function every time in the performance of the code. Angular.noop can create a strong coupling with angular objects.