DEV Community

Discussion on: JavaScript Callbacks Explained in 5 Minutes

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ • Edited

Callback functions are functions that are passed as a parameter to another function

It's not as simple as this. To be considered a callback, it really needs to be called by the code it is passed to.

Collapse
 
jamesqquick profile image
James Q Quick

This is a great clarification. I can't think of a reasonable scenario where you would pass a function without the expectation that it's going to be called. Because of that, I think it would be implied, but this is a great callout.

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ • Edited

A few random possibilities off the top of my head:

  • A function to wrap another function and return the wrapped version (debounce springs to mind)
  • A function to compose one or more functions, and return the new one.
  • A function to return the arity of the passed function
  • A function to display the source of the passed function