when I'm debugging javascript I'm constantly running into situations where due to scope issues I'm not able to access variables that were suppose to be provided to me by closure.
I can traverse up a stack level to put myself in the correct scope for this case, but this is quite confusing and doesn't do the trick when you deal with promises / async calls.
I believe this is a feature where garbage collector marks and sweeps unused variables (correct me if I'm wrong).
Is there a mode that I can turn to in order to preserve closure variables (and yes I realize this could cause nothing to be garbage collected, but still useful to have when debugging and should not impact the behavior of the app)
code with this issue:
function hello(arr, foo, bar) {
arr.forEach(item => {
debugger; // HERE `foo`, `arr` and `bar` are reference errors in debugger evaluation
});
return 1
}
hello([1,2,3], 'foo', 'bar')
------------edit-------------
UPDATED EXAMPLE