The return function is the function that ends the execution and will return a value to the function caller. The purpose of the return function when coding is to end the execution of the return, and as I previously mentioned as well, returns the control to the calling function. Below I will provide an example of a return function as well:
function multiplyTwonumbers(a,b) {
var result = a * b;
return result;
}
the return function stops the execution of a function and will return the value from it as well. Above you can see an example I included, and show in the code where the return function was executed, which would return the value from the code.
After doing a little more research about the return function, I learned more about the definition of currying as well. Currying is defined as, the transformation of a function with multiple arguments that is put into a sequence in a single-argument function. This means that you can have multiple step functions, but when using the return function, you do not have to go all the way back in your steps to figure out what passed that was able to return the function. After reading this new term, I was intrigued to know the benefits that a return function can also have.
Hi Jessica, thanks for your post! Honestly, I never understood return that well. What confuses me is that it returns the function caller, but it doesn’t print or log it anywhere. I have a hard time visualizing where that data goes. Is it stored in the function caller? Can you then log the variable that was returned and see the result? It is still confusing to me.