0

Can we pass a function with parameters as a callback function ?

19th Apr 2021, 5:40 PM
LIGHT
LIGHT - avatar
2 Réponses
+ 5
No if you do that it will call the function you put as an argument itself, plus that beats the purpose
19th Apr 2021, 5:53 PM
「HAPPY TO HELP」
「HAPPY TO HELP」 - avatar
0
You can pass arguments to a callback by wrapping it in another function. I've made a little, basic demo. https://code.sololearn.com/Wn4Y7HVdUkcU/?ref=app Being able to handle arguments is very useful for callbacks, just as for other functions. For example, several in-built array methods take a callback function with multiple parameters. E.g. map, filter, reduce etc.
20th Apr 2021, 2:32 AM
CamelBeatsSnake
CamelBeatsSnake - avatar