Javacript closure concept question?
Please help me understand this code.
// the answer is 40.
// Question: What is the value of result.
var hidden = mystery(4);
var result = hidden(2);
function mystery ( input ){
var secret = 5;
function mystery2 ( multiplier ) {
multiplier *= input; // 4 * 2
return secret * multiplier; // 5 * 8 = 40
}
return mystery2;
}
So pretty much I'm trying to understand the concept. Is my math in comments correct? I am having trouble understanding how 2 inside hidden(2) and 4 in mystery(4) became multiplier and secret. This part is so mind numbing please someone explain this to me step by step. Thank you so much!
Special Offers
Portfolio
Testimonials