while I'm trying to understand JS closures, i wrote this code :
const outer = function() {
let a = 10, c = 100;
const inner = function() {
let b = 20;
console.log(a + b); // line 5 (30)
};
return inner;
};
let K = outer();
console.log(K()); // line 10 (undefined)
The console's output:
30 ( line 5)
undefined ( line 10 )
the console outputs the result ( 30 )
and it points to (line 5) of the code ( this seems reasonable for me ) after that ( and that's what I didn't understand) it returns undefined when it gets back to the last line of code ( line 10 ) Anyone can clarify this JS behavior?