I'm under the impression that my variable scope should be correct, but the value isn't getting set. I'm wondering why that might be.
Here's my code:
function getUserStatus() {
var status;
function querySuccess(tx, results) {
var row = results.rows.item(0);
console.log(row['id']);
status = {
question: row['id']
};
}
function errorCB(err) {
console.log(err);
}
db.transaction(function(tx) {
tx.executeSql('SELECT id FROM calculator ORDER by id ASC LIMIT 1', [], querySuccess, errorCB);
});
console.log(status);
return status;
}
Now, the status variable inside the querySuccess() function is getting set correctly - I am getting a value of 1 for it.
However when I check the second variable of status, outside the scope of the function, I am getting undefined.
Am I misunderstanding Javascript variable scope or declaring my variables incorrectly? I'm new to Javascript.