When is a Function considered a Callback Function?

On the Thinkful Slack channel last week, someone asked a seemingly simple question about functions inside another function’s arguments:

within a route like app.get(‘/test’, someFunction(), (req, res) => etc etc, is someFunction() called an inner function? Does anyone know the technical name for that?

They got a very good answer which I think was close to perfect:

inner is more a generic term, not specific to functions. e.g. you could refer to inner and outer scope

  1. .get() is a higher order function because it takes one or more functions as a parameter

  2. someFunction is often termed a “callback” because it’s a function that’s intended to be called at a later time

  3. both someFunction and (req, res) => {} defined above are callback functions

They were right about the first part, that .get() was a higher order function.

They were right about the second part, that someFunction implies it can be called later.

They were even right about the final final part, where they called the anonymous inline ES6 “fat arrow” function (req, res) => {} a callback.

However, something kept nagging me about the difference between someFunction() in the question and someFunction in the final answer. Hidden in that lack of parentheses is a world of difference.

To elaborate, I offered the following comment to the channel, which sparked a conversation for further clarification. I reproduce it here in the hopes that it may help more programming students understand function semantics better.

Continue reading “When is a Function considered a Callback Function?”