我宣佈變量,我想返回改變變量的值作爲外部函數的值,但目前越來越undefined.Plz提供指導。如何從外部函數在功能全球水平,這最終會內部函數內改變訪問內部函數的性質與JavaScript
function checkResult(req){
let result = true;
Reservation.find({result_date: req.body.res_date}, function (err,doc) {
if (err) {console.log(err);}
else if (reservations) {
result = false;
console.log(result);
}
})
console.log("Final:");
return result; // undefined error
}
reservation.find做什麼?最重要的是,它是異步的嗎? –
的可能的複製[如何返回從一個異步調用的響應?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – marvel308