You want to limit the scope of variables to just the location they are needed. If a variable is only needed in a function use var, let or const. If you use this.x unnecessarily then another function in the same script could unexpectedly overwrite it - causing problems. By the way, result = ...
wasn’t the only unintentional global variable use in your code mentioned above. You need to fix the other cases too.
1 Like
Well I didnt write that particular part someone else did, so I was unaware of the issue.
It’s good that you are aware now. If you are planning to release this code as a tutorial then it would be good to fix these issues.