I am running into a strange scope issue with Javascript (see JSFiddle):
var someGlobal = 3;
function someF() {
// undefined issue
alert(someGlobal);
Here is an example of how to use both the local and global variable inside someF
by using this
.
var someGlobal = 3;
function someF() {
// Displays 3
alert(someGlobal);
this.someGlobal = 5;
someGlobal = 5;
// Displays 5
alert(this.someGlobal);
}
function someF2() {
// Displays 5
alert(someGlobal);
}
someF();
someF2();