Skip to main content

Command Palette

Search for a command to run...

Anonymous Function in JavaScript

anonymous function

Published
•1 min read•View as Markdown
Anonymous Function in JavaScript
A

I am a inspiring developer in the field of web development and also intersted in open source contributions.

  • 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 ;

}