Excellent article! By the way, I did not catch why is it useful to return a function as an output... could anybody please give me a practical example? Thanks.
let's say we want to create a greeter function that will take a greeting copy but we know that this copy will change depending on the context.
we can do:
constgreeter=copy=>{returnname=>`${name}${copy}`}constpoliteGreeter=greeter('you are very welcome here')constweirdGreeter=greeter('you look weird today!')console.log(politeGreeter('Ysael'))// Ysael you are very welcome hereconsole.log(weirdGreeter('Ysael'))// Ysael you look weird today!
witch will allow us to make different greeter functions.
Hope that helps :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Excellent article! By the way, I did not catch why is it useful to return a function as an output... could anybody please give me a practical example? Thanks.
If your code had to call a function depending on some other logic, you could return the function to call from the function that decides. Make sense?
You mean something like returning different functions in a switch statement, for example?
Right
Now I get it, thanks!
Hi Alvaro,
thanks :)
let's say we want to create a greeter function that will take a greeting copy but we know that this copy will change depending on the context.
we can do:
witch will allow us to make different greeter functions.
Hope that helps :)