I'm trying to define a global variable value, from a function which is executed with the timeout method. The problem I'm facing here is can't get rid of the time interval.
*** Not Working (But I want the goal variable to be outside so that I can access it later).
function demo() {
var noOfGoals = 4;
goal = "He has scored " + noOfGoals + " in 45 Mins";
}
setTimeout(function() {
demo();
}, 2000);
console.log(goal);
****Working(but I dont want to access it from setTimeout)
function demo() {
var noOfGoals = 4;
goal = "He has scored " + noOfGoals + " in 45 Mins";
}
setTimeout(function() {
demo();
console.log(goal);
}, 2000);
Any new ideas or a better apporach than how have I done!