I have to select all tags available in the database, so I could use them in my function, but I can't use the variable after I assigned a value to the variable in the callback function of the query, why?
Code which is not working:
let tags = [];
db.query(
`select * from tags`,
(err, results) => {
tags = results;
}
)
console.log(tags);
return;
However this works:
let tags = [];
db.query(
`select * from tags`,
(err, results) => {
tags = results;
console.log(tags);
}
)
return;
but why? I want to use the variable tags
after that query again, but somehow the value assigned to it is destroyed after the query. What would I have to change?