For some reason when I try to access the rates
variable inside the for-in
loop, it throws a ReferenceError
, but I can use it just fine right before the loop. I can't seem to figure out what is causing this behavior. Even doing typeof
throws this error, but it works fine on a variable that was never used at all:
const test = 1;
const rates = await Rate.find({
propertyId: property._id,
ratePlanId: {$in: ratePlanIds},
});
console.log(test); // 1
console.log(typeof rates); // object
for (const i in ratePlans) {
console.log(test); // 1
console.log(typeof asdlkfjasdajsfl); // undefined
console.log(typeof rates); // ReferenceError: rates is not defined
//[... rest of code]
}