Access global variable from a function, which has same variable name

How to access global variable from a function, which has same variable name in java script.

You can use the window object to get the global variable.
e.g. window.variableName
Here we write an example
var blogName = "webspeckle";
var blog = function()
{
    var blogName = window.blogName || "";
    return blogName;
}
blog();

//The output is 'webspeckle'


No comments:

Post a Comment