Request Dev Services » / Notes /

What is an anonymous function in JavaScript?!

  • An anonymous function, is basically a function without a name or may also be referred to as a self-invoking inline function.
  • Take functions stored in variables, for instance, if it is only ever called in one place, then there is not really much a reason to name whatever namespace you’re in. They can be invoked (or called) simply using the variable name.
  • Anonymous functions are used in JavaScript for many things, probably one most common use is the many callbacks used by the language’s many frameworks.
  • Anonymous functions are declared inline which allow advantages in that they can access variables in the parent scopes. Names can be added to an anonymous function, but usually defeats the purpose if it’s declared inline.
  • Anonymous functions are useful to pass as arguments to other functions. Additional uses can be found pertaining to hoisting and lexical scoping.

Example of an anonymous function:

var teams = [2,4,6];
var teams_half = {
return item / 2;


About the Author
Cameron Cashwell Web Developer
I build websites, web apps, and software. Wanna work together? Let's chat about your project!

Leave a Reply

Be the First to Comment!

Notify of