Difference between callback function and lambda function?

Difference between callback function and lambda function?
0

#1

Tell us what’s happening:
First see this :-1:

When the functions are passed in to another function or returned from another function, then those functions which gets passed in or returned can be called a lambda

Callbacks are the functions that are slipped or passed into another function to decide the invocation of that function.

Now, callback function are functions that are passed as argument to another function
According to definition of lambda functions that is the same case as with callback…

That means I can say a callback function is a lambda function ?
OR
Both are different?

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/functional-programming/understand-functional-programming-terminology/


#2

Lambda function are anonymous functions. Callback can be named or anonymous.
So all lambda functions can be a callback function but not all callback function can be lambda function.


#4

You should take a look at this article:


#5

Going by wikipedia:

In computer programming, an anonymous function ( function literal , lambda abstraction , or lambda expression ) is a function definition that is not bound to an identifier.

or this SO post:

Lambda comes from the Lambda Calculus and refers to anonymous functions in programming.

Unlike Python (where the language itself calls anonymous function lambda), JS doesnt mention anything about lambda function. You can check the specification yourself.
I think arguing about this is a moot point, the distinction (even if there was one) is not a breaking deal.

I dont see anyone going around calling people out if they use parameter/argument, function/method, library/framework interchangeably even though they are not same. IMO its too pedantic.

Coming to your original question:

That means I can say a callback function is a lambda function ?

I’d say “no”, according to the popular definition of lambda.
Callback functions can be bound to an identifier therefore can be a named function too.


#6

can you tell what you mean by bound to identifier?


#7
const someNameForThisFunction = () => {
  /* This anonymous function is bound to  someNameForThisFunction */
};

JS doesn’t have lambdas according to the strict definition, but because functions are first-class values, they can act in exactly the same way, it makes no difference if they are given a name or not


#8

Bound to an identifier means the function can be referenced. Every function have a .name property. Anonymous functions have "" as .name.

Example:

function add10(callback){
  console.log(callback.name); 
  return 10 + callback();
}
function someFunc(){
  return 5;
}
add10(someFunc); 
/*
someFunc
15
*/

Note you can also reference these function inside themselves meaning recursion is possible, but you cannot reference an anonymous function.
The same example with anonymous function:

function add10(callback){
  console.log(callback.name); 
  return 10 + callback();
}
add10(function(){
  return 5;
});
/*
""
15
*/

Notice the empty string in the output, its because the function is not bound to an identifier but is still a callback function.