I want to change a certain variable every second. But the same variable is changing on multiple places of them, and one of them is resulting in NaN. I can't seem to find out what exactly is causing that. Is there a way to log the stack trace where it changes? Take for example this code:
let foo = 0;
for (foo = 0; foo < 5; foo++) {
// Do something
}
if (isNaN(foo)) {
// Console.log the stack trace where the variable changes into NaN
}
Is it possible to do this in one, two or three lines without having to change too much logic or adding too much things in order for it to work? It is node.js-compatible, so it can be a NPM package if that's easier.
typescript, but didn't givefooa type. Several (not all) causes ofNaNsurfacing as a result in JavaScript could be avoided by using TypeScript where you type all the variables that have anything to do with assignments tofoo.foois actually inside an object, you could make it a setter or aProxyand capturenew Error().stackon every set