Problem: I want to make a variable inside a function as a global variable
This works:
var x;
function myFunction() {
x = 999;
}
myFunction();
console.log(x);
But this one doesn't work while trying to declare a global variable from API Result
webOS.service.request(url, {
onSuccess: function (data) {
var serial = data.idList[0].idValue;
var udid = serial; // This is the variable that I want
callback(udid); // Trying to get this udid out of this API call
},
});
var sn;
function callback(udid) {
sn = udid; // I want this as my global variable
}
callback(udid); // produces an error which says udid not defined
console.log(sn); // undefined
How can I make var sn as global variable? Thanks in advance