I am struggling to comprehend why the variable "productsAvailable" still shows true even after being set to false.
router.post('/api/transactions', (req, res) => {
var productsAvailable = true
for(var i=0; i<3; i++) {
ProductM.findOne({name:"not available name"}).exec((err, product) => {
productsAvailable=false //changed to false
})
console.log(productsAvailable) //this displays as true
}
})
Thank you