Hi everyone, I was learning closures in JS here on MDN, so I saw an example that I have doubts:
var getCode = (function () {
var secureCode = "0]Eal(eh&2"; // A code we don't want external persons be able to change
return function () {
return secureCode;
};
})();
getCode(); // Returns secureCode
I understood the use of IIFE and how it returned the code… my question is:
what would be the difference if I don’t use closure and just return secureCode? Would people be able to change the variable without closure? If so, how?
Thanks in advance!