javascript - Access overridden global variable inside a function -


i want access global variable 'x' when over-ridden same named variable inside function.

function outer() {    var x = 10;    function overridex() {       var x = "updated";       console.log(x);    };    overridex(); }  outer(); 

jsbin : fiddle test

i don't want rename inner 'x' variable else. possible ?

edit: edited question after abeisgreat answer.

you can use window.x reference globally scoped variable.

var x = 10; function overridex() {   var x = "updated";   console.log(x);   console.log(window.x); };  overridex(); 

this code logs "updated" 10.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -