I have the following code-
let { user } = req.body;
let name = null;
if (!user) {
getStudent(id).then((x) => {
user = x.user;
name = x.name;
});
}
console.log(user, name); // prints undefined and null
Though I'm using let that will reassign the values, seems it's not getting updated here. Anyone knows why?
Edit- i have put console.log inside then as per comments , it's resolved. But i have one more async function below it that needs it's value, so what can I do?