I’m skirting around the issue, but the point is that you need to demand to be in control of every single operation you carry out and be willing to observe everything you do.
When you’re writing a function you’d presumably be concerned only with what happens between the input and output of that function.
And you can print out a log of all the things you’re doing, ensuring the order of actions makes sense and that… they’re happening at all.
So maybe you’d do
console.log("about to call my function")
let result = myfunction()
console.log("the function returned! its result was:", result)
and everything you expected to happen in your function, which you’d be writing out to observe them, would be printing between those two. if anything was outside then… that would say something about the problem.
So you would expect an output like this:
about to call my function
calling some other function
that other function's result was 3
setting my variable to 3
hey look i can read it back: 3
adding 5 to 3, i get: 8
the function returned! its result was: 8