I am in need of clarification on a JavaScript concept that is confusing for me as a beginner. I have come across the following code snippet and I am having trouble understanding how it works:
function multiple(n) {
function f(x) {
return x * n;
}
return f;
}
var triple = multiple(3);
var quadruple = multiple(4);
Upon using the console to execute the following line of code:
console.log(triple(5));
I am getting the expected output, which is 15. This logic seems to work correctly with any number passed in (tripling or quadrupling based on the function used).
However, upon typing 'triple' into the console, I receive this block of code:
f(x) {
return x * n;
}
Shouldn't the console instead display...
f(x) {
return x * 3;
}
...as the number 3 is explicitly defined in the function by the statement:
var triple = multiple(3);