This question can be answered elsewhere, but I was not even sure how to start the search for the answer. I am new to JavaScript, so this is a fight for me to understand.
Given the following code:
function multiple(n) { function f(x) { return x * n; } return f; } var triple = multiple(3); var quadruple = multiple(4);
When I pass the following to the console:
console.log(triple(5));
I get what I expect, that is 15. Similarly, with any number, it will be tripled (or quadrupled if I use the second function).
But when I enter the triple into the console, I get the following code:
f(x) { return x * n; }
Do not return the console ...
f(x) { return x * 3; }
... since 3 is encoded into a function by virtue of the following code:
var triple = multiple(3);
source share