DEV Community

Discussion on: Understanding the .map(), .filter() and .reduce() array methods in Javascript.

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

I wish people would stop referring to all functions that are passed in to other functions as 'callback functions'. It gives the misleading impression that they are somehow different or special in some way, when in fact they are just plain, ordinary functions. Giving them a fancy name just introduces unnecessary confusion to new developers, where there need not be any.

It only really makes sense to refer to them as 'callback' functions when they are passed into a function that performs an asynchronous task which will finish at some indeterminate time in the future - at which point, the function will be "called back" to tell you it's done. That is where the name comes from.

Collapse
 
frankwisniewski profile image
Frank Wisniewski • Edited
Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

Yeah, definitions vary... but I do feel it introduces unnecessary confusion - especially when not explained clearly (which I am indeed a little guilty of above). I see people refer to passed functions as 'callbacks' even when they are not called - i.e. in a function that wraps the passed function then returns the wrapped version - so confusion clearly exists. It is not as simple as 'every function passed to another function is a callback function', which I've heard variations of from many junior devs / interviewees.

The key part in the Wikipedia definition is:

that code is expected to call back (execute) the callback function as part of its job

Thread Thread
 
frankwisniewski profile image
Frank Wisniewski

for me it's just a function. Some see it differently. It's getting on my nerves that filter, map and reduce are talked about here every few days.....

Thread Thread
 
jonrandy profile image
Jon Randy 🎖️ • Edited

Haha, yep. Dev should introduce a feature when you post to check if you're effectively reposting content from existing documentation, and attempt to discourage you from doing so.