0

Anonymous function in javascript

What is anonymous function in javascript?explain with an example.

23rd Dec 2019, 7:37 AM
swali1
4 Respuestas
+ 2
It's a function that was declared but not assigned to any name indentifier, thus, it cannot be used again after its initial declaration. A non-anonymous function would be written as: ___ function hello(){ return 'hello' } ___ or ___ const hello = () = { return 'hello' } ___ A anonymous function would be written as: ___ function() { return 'anonymous' } ___ or ___ () = { return 'anonymous'} ___ It has many uses but 90% of the time you'll use it in Higher Order Functions as an argument, for example, doubling all numbers of an array with the map method: ___ const nums = [1, 2, 3] //Double all numbers with an anonymous arrow function const doubles = nums.map( num => { return num * 2} ) //Output [2, 4, 9] console.log(doubles) ___
23rd Dec 2019, 6:33 PM
oh Common
oh Common - avatar
+ 2
wow!thanks!👍👍👍
1st Jan 2020, 2:28 AM
swali1
0
Hey, just noticed a mistake. The output should be [2, 4, 6], lol. Anonymous functions are also common as callbacks. Sorry!
1st Jan 2020, 5:00 AM
oh Common
oh Common - avatar
0
lol..its ok 😂😅
2nd Jan 2020, 8:56 AM
swali1