javascriptanonymous-function

Are anonymous functions a bad practice in JavaScript?


I was reading that using anonymous functions in javascript is bad practice, because it can make debugging a pain, but I haven't seen this for myself. Are anonymous functions in JavaScript really bad practice and, if so, why?


Solution

  • Nope, anonymous functions are used all over the place in JavaScript across the web. It may make debugging a little more difficult in spots, but not nearly enough to say that they shouldn't be used.

    For example, JQuery makes extensive use of them.

    There are a lot of times when you want to use them over formally declared functions, such as when you want to limit their scope.