0

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]
}
Mike
  • 20,721
  • 13
  • 66
  • 79
  • 1
    This means you have defined another `let rates`, `const rates` or `class rates {}` in that `for` loop body, below that part which you did show us. You experience the temporal dead zone. – Bergi Sep 11 '20 at 23:38
  • @Bergi Ohhh. It's further down. Thanks! – Mike Sep 11 '20 at 23:40

0 Answers0