I think I know the answer but... is there any way to prevent a global variable from being modified by later-executing ? I know global variables ar
Instead of declaring all such variables in the global scope, you could have one global object wrapping around those variables. Using Object.defineProperty() and/or Object.defineProperties() with the writable flag set to false, you can have an immutable variable.
var myObj = {};
Object.defineProperty(myObj, 'myVar', {
value: someValue,
writable: false
});
Or you could just use the const keyword
const MY_VAR = 10;