(function () { var privateNumberScriptLoaded; if (typeof numberScriptLoaded === "undefined") { // Assigning to window.numberScriptLoaded creates the global window.numberScriptLoaded = 1; // 1, not 0 } else { ++numberScriptLoaded; } // Note that all `window` properties are globals, // so here, it works even without the prefix privateNumberScriptLoaded = numberScriptLoaded; console.log("Option 3: privateNumberScriptLoaded = " + privateNumberScriptLoaded); })();