Is there any way to modify variables accessed using closures and have no way to access them










0















I just now saw an example of closures in Javascript MDN website. Which is this:






var getCode = (function() 
var apiCode = '0]Eal(eh&2'; // A code we do not want outsiders to be able to modify...

return function()
return apiCode;
;
)();

console.log(getCode()); // Returns the apiCode





I'm a beginner and I want to know Is apiCode variable in the code completely unaccessible. Or if there is any way to modify its value










share|improve this question

















  • 1





    It's only accessible from within the getCode method.

    – Adriani6
    Nov 12 '18 at 14:48






  • 3





    There is NO WAY to protect code that is available on the browser. Set a breakpoint and change the variable. TADA. Override the function from the console, set it to whatever you want. Hijack the http request with a proxy, alter it anyway you want.

    – epascarello
    Nov 12 '18 at 14:50












  • @Adriani6 Does it mean that it is unaccessible without changing the code?

    – Hemanbabu
    Nov 12 '18 at 14:50







  • 2





    @Hemanbabu Yes. That's the point of a closure. But note what the 2nd comment said. That's fundamentals of client-side development. It all depends on what you mean by accessing the variable. Programatically? Then you're good, anything else you're not good.

    – Adriani6
    Nov 12 '18 at 15:00












  • It is protected in a sense that noone can modify it, but everyone can see it, that is for sure.

    – Dellirium
    Nov 12 '18 at 15:06















0















I just now saw an example of closures in Javascript MDN website. Which is this:






var getCode = (function() 
var apiCode = '0]Eal(eh&2'; // A code we do not want outsiders to be able to modify...

return function()
return apiCode;
;
)();

console.log(getCode()); // Returns the apiCode





I'm a beginner and I want to know Is apiCode variable in the code completely unaccessible. Or if there is any way to modify its value










share|improve this question

















  • 1





    It's only accessible from within the getCode method.

    – Adriani6
    Nov 12 '18 at 14:48






  • 3





    There is NO WAY to protect code that is available on the browser. Set a breakpoint and change the variable. TADA. Override the function from the console, set it to whatever you want. Hijack the http request with a proxy, alter it anyway you want.

    – epascarello
    Nov 12 '18 at 14:50












  • @Adriani6 Does it mean that it is unaccessible without changing the code?

    – Hemanbabu
    Nov 12 '18 at 14:50







  • 2





    @Hemanbabu Yes. That's the point of a closure. But note what the 2nd comment said. That's fundamentals of client-side development. It all depends on what you mean by accessing the variable. Programatically? Then you're good, anything else you're not good.

    – Adriani6
    Nov 12 '18 at 15:00












  • It is protected in a sense that noone can modify it, but everyone can see it, that is for sure.

    – Dellirium
    Nov 12 '18 at 15:06













0












0








0








I just now saw an example of closures in Javascript MDN website. Which is this:






var getCode = (function() 
var apiCode = '0]Eal(eh&2'; // A code we do not want outsiders to be able to modify...

return function()
return apiCode;
;
)();

console.log(getCode()); // Returns the apiCode





I'm a beginner and I want to know Is apiCode variable in the code completely unaccessible. Or if there is any way to modify its value










share|improve this question














I just now saw an example of closures in Javascript MDN website. Which is this:






var getCode = (function() 
var apiCode = '0]Eal(eh&2'; // A code we do not want outsiders to be able to modify...

return function()
return apiCode;
;
)();

console.log(getCode()); // Returns the apiCode





I'm a beginner and I want to know Is apiCode variable in the code completely unaccessible. Or if there is any way to modify its value






var getCode = (function() 
var apiCode = '0]Eal(eh&2'; // A code we do not want outsiders to be able to modify...

return function()
return apiCode;
;
)();

console.log(getCode()); // Returns the apiCode





var getCode = (function() 
var apiCode = '0]Eal(eh&2'; // A code we do not want outsiders to be able to modify...

return function()
return apiCode;
;
)();

console.log(getCode()); // Returns the apiCode






javascript ecmascript-6 ecmascript-5 ecmascript-2016






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 12 '18 at 14:46









HemanbabuHemanbabu

13412




13412







  • 1





    It's only accessible from within the getCode method.

    – Adriani6
    Nov 12 '18 at 14:48






  • 3





    There is NO WAY to protect code that is available on the browser. Set a breakpoint and change the variable. TADA. Override the function from the console, set it to whatever you want. Hijack the http request with a proxy, alter it anyway you want.

    – epascarello
    Nov 12 '18 at 14:50












  • @Adriani6 Does it mean that it is unaccessible without changing the code?

    – Hemanbabu
    Nov 12 '18 at 14:50







  • 2





    @Hemanbabu Yes. That's the point of a closure. But note what the 2nd comment said. That's fundamentals of client-side development. It all depends on what you mean by accessing the variable. Programatically? Then you're good, anything else you're not good.

    – Adriani6
    Nov 12 '18 at 15:00












  • It is protected in a sense that noone can modify it, but everyone can see it, that is for sure.

    – Dellirium
    Nov 12 '18 at 15:06












  • 1





    It's only accessible from within the getCode method.

    – Adriani6
    Nov 12 '18 at 14:48






  • 3





    There is NO WAY to protect code that is available on the browser. Set a breakpoint and change the variable. TADA. Override the function from the console, set it to whatever you want. Hijack the http request with a proxy, alter it anyway you want.

    – epascarello
    Nov 12 '18 at 14:50












  • @Adriani6 Does it mean that it is unaccessible without changing the code?

    – Hemanbabu
    Nov 12 '18 at 14:50







  • 2





    @Hemanbabu Yes. That's the point of a closure. But note what the 2nd comment said. That's fundamentals of client-side development. It all depends on what you mean by accessing the variable. Programatically? Then you're good, anything else you're not good.

    – Adriani6
    Nov 12 '18 at 15:00












  • It is protected in a sense that noone can modify it, but everyone can see it, that is for sure.

    – Dellirium
    Nov 12 '18 at 15:06







1




1





It's only accessible from within the getCode method.

– Adriani6
Nov 12 '18 at 14:48





It's only accessible from within the getCode method.

– Adriani6
Nov 12 '18 at 14:48




3




3





There is NO WAY to protect code that is available on the browser. Set a breakpoint and change the variable. TADA. Override the function from the console, set it to whatever you want. Hijack the http request with a proxy, alter it anyway you want.

– epascarello
Nov 12 '18 at 14:50






There is NO WAY to protect code that is available on the browser. Set a breakpoint and change the variable. TADA. Override the function from the console, set it to whatever you want. Hijack the http request with a proxy, alter it anyway you want.

– epascarello
Nov 12 '18 at 14:50














@Adriani6 Does it mean that it is unaccessible without changing the code?

– Hemanbabu
Nov 12 '18 at 14:50






@Adriani6 Does it mean that it is unaccessible without changing the code?

– Hemanbabu
Nov 12 '18 at 14:50





2




2





@Hemanbabu Yes. That's the point of a closure. But note what the 2nd comment said. That's fundamentals of client-side development. It all depends on what you mean by accessing the variable. Programatically? Then you're good, anything else you're not good.

– Adriani6
Nov 12 '18 at 15:00






@Hemanbabu Yes. That's the point of a closure. But note what the 2nd comment said. That's fundamentals of client-side development. It all depends on what you mean by accessing the variable. Programatically? Then you're good, anything else you're not good.

– Adriani6
Nov 12 '18 at 15:00














It is protected in a sense that noone can modify it, but everyone can see it, that is for sure.

– Dellirium
Nov 12 '18 at 15:06





It is protected in a sense that noone can modify it, but everyone can see it, that is for sure.

– Dellirium
Nov 12 '18 at 15:06












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264578%2fis-there-any-way-to-modify-variables-accessed-using-closures-and-have-no-way-to%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53264578%2fis-there-any-way-to-modify-variables-accessed-using-closures-and-have-no-way-to%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20