Answer the question
In order to leave comments, you need to log in
Write a sum function that works like this: sum(a)(b) = a+b, how to understand 2 returns?
Hello everyone, how to understand two returns? I understand that this is a return value, but in more detail? and 2 returns do closures? thanks
Write a sum function that works like this: sum(a)(b) = a+b
function sum(a ) {
return function(b) {
return a + b;
};
}
alert( sum(1)(2) ); //3
alert( sum(5)(-1) ); //4
Answer the question
In order to leave comments, you need to log in
This means that the sum function will return another function
function sum() {
return function() {
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question