I am learning about Persistent Lexical Scope References when it comes to function memory in JS. It caused me to reflect on what the parentheses are actually doing when it comes to function calls.
If I store a function inside a variable, that variable contains/has access to a function definition and return value, correct?
So, when the JS engine sees () after a function label, it knows to call the functionality associated with that label and executes accordingly producing a return value.
Please let me know if I am missing anything with this logic. Thanks!
function myFunc() {
let x = 0;
function inner() {
x++;
};
return inner;
}
let another1 = myFunc(); // stores the functionality of inner();
another1(); // JS engine runs inner() which increments and stores the value of x to be used again;