- Anonymous functions in JavaScript, are the functions that do not have any name.
- Anonymous functions(reference) are stored in variables. They are always invoked (called) using the variable name.
- We can write an anonymous function using the function keyword, followed by parentheses (param1,param2,...) and then the curly braces, the same as we do for normal functions in any language.
- Some important use cases:
- Anonymous functions are used a lot as callback functions.
- It's useful when we want any function to be invoked right after it is declared.
- It is used a lot, for different eventhandlers in js.
- It's more useful, when a function is to be used only once.
- There is another type of function in JS which can be called as a type of anonymous function, Which is the Arrow Fucntions:
- => is the representation for arrow functions.
- They are the more compact and shorter way, to write anonymous functions.
Created
September 18, 2022 20:06
-
-
Save srijoy-paul/77dc3737389bba1fcb8a8d1506085bed to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment