I am trying to grasp execution contexts and have a question around for loops.
Consider the following...
function copyArrayAndMutate(array, instructions) {
let output = []
for(let i = 0; i < array.length; i++) {
output.push(instructions(array[i]));
}
return output;
}
function multiplyByTwo(input) {
return input * 2;
}
const result = copyArrayAndMutate([1,2,3], multiplyByTwo)
At a high level, I understand that these functions will be defined in the Global Execution Context, once invoked, they will create their own local execution context and the thread of execution will move into that context, with entries for the context being pushed to the stack.
My question is, will the for loop have it's own execution context? If so, and an execution context has it's own memory, how does output still exist within that for loop's context?
Is this because the local execution context of the for loop, exists within context of copyArrayAndMutate?