vertti vertti - 10 months ago 57
Javascript Question

Nested call to function in Javascript

Intellij IDEA shows a warning when ever I write Javascript like this:


But the explanation is not really helpful:

"This inspection reports any Javascript function calls used as
arguments to another function call."

This is something I do frequently, so what's the potential trap hiding there worth warning of? Or if it's just some coding convention, what's the reason for it?


It is a warning because most of the time, you want to pass a function reference as an argument. It is mostly used as a callback:


In that example, someOtherFunction() instead of someOtherFunction would not work as expect (unless someOtherFunction returns a function itself).

someFunction(someOtherFunction()); work more like a getter.

    alert(int === 1);//True;
    return 1;

It gives a warning because it is a common mistake for new developers.