I am new to JavaScript. I don't get it why it prints the value undefined on the console before the correct id.
I am trying to return the inserted id yet I get an "undefined" on the return, but the console shows the correct id.
VisaFam.dbs.addFamily = function(nom) {
var db = VisaFam.dbs.db;
var family_id;
db.transaction(function(tx) {
tx.executeSql("INSERT INTO family (nom) VALUES (?)",
[nom],function(tx, results){
family_id= results.insertId; //i want to return this
console.log(results.insertId); // this prints the correct value
});
});
console.log(family_id); // this shows undefined
return family_id; // the return is thus "undefined"
}