// Example: Function Returning a Function
// function multiple(x) {
function fn(y)
{
return x * y;
}
return fn;
}
var triple = multiple(3);
triple(2); // returns 6
triple(3); // returns 9
/* I learned BASIC programming a long time ago and was taught to think logically when programming but there seems to be much explanation left out in breaking down for a beginner in Javascript, I have learned in this course how to call a function whilst at the same time passing a value to its parameter to be used within that function block. We are given several easy-to-understand examples and then we are given the code of a function calling another function with no proper breakdown of how it works. If var triple = multiple(3) then triple = the value in multiple(3).
Also when var triple is created as equal to multiple(3), does it automatically become triple(3).
Also function fn(y) is a named function within the multiple(3) function, so why isnāt fn(y) called?
Youāve explained that triple(y) is fn(y) so why create triple(y) instead of just calling fn(y)
I know the program must work, so what am I missing here? Is fn a reserved word for a function that is automatically given a call variable such as triple(y)
please can you break it down a little bit more based on my confusion?
I canāt progress any further until I understand how this works. Iāve seen examples of functions calling other functions in a simple call stack example and understood them but not so much when they give a more complex but shorter version for the same result for more advanced students. Could it be that the example Iāve been given isnāt for a beginner to understand and I shouldnāt try to figure it out because of my limited java knowledge and just move on?
Can someone simplify what each line of code does, so that I can make sense of it? Thank you.
*/