Anonymous Function in JavaScript

Anonymous Function in JavaScript

anonymous function

  • It is a function that does not have any name associated with it. Normally we use the function keyword before the function name to define a function in JavaScript.

  • However, in anonymous functions in JavaScript, we use only the function keyword without the function name.

  • An anonymous function is not accessible after its initial creation, it can only be accessed by a variable it is stored in as a function as a value.

  • An anonymous function can also have multiple arguments, but only one expression.

Example -

  • Here we define the declaration of an anonymous function using the normal declaration:

function () {

// code to be executed ;

}