0

I have going through some of the documents on function currying and all docs reflects 'closure' by means of 'currying'. so, i doubt how can differentiate between closure and currying?

Have already gone through here and it does not have any marked answer Does curry function in javascript uses principle of closure?

this below code

var greet = function(greeting, name) {
  console.log(greeting + ", " + name);
};
greet("Hello", "world"); //"Hello, world"

rewritten as (currying) (But, i understand this below code is 'closure')

var greetCurried = function(greeting) {
  return function(name) {
    console.log(greeting + ", " + name);
  };
};

here is the results that i got:

var greetHello = greetCurried("Hello");
greetHello("World!"); //"Hello, World!"
greetHello("Universe!"); //"Hello, Universe!"

the above code represents the 'closure'. if so, how can i differentiate between closure and currying please?

How to differentiate differentiate between closure and currying in javascript

Community
  • 1
  • 1
User123
  • 453
  • 2
  • 6
  • 17
  • @Danial A. White I already read that, but, it does not hold any valuable answer.. this is why i put this question here.. Could you please give your comments why this is duplicate? – User123 Feb 24 '16 at 13:51
  • `greetCurried` is curried because it returns another function to take more arguments. `greetHello` is a closure because it closes over `greeting`. – Bergi Feb 24 '16 at 14:21

0 Answers0