I’m working on the OOP JavaScript lessons, and I ran into a point of confusion regarding the syntax of for/in loops. I am iterating over the following example object’s properties like so:
let canary = { name: 'Tweety', numLegs: 2 }
// Example uses a constructor, but I wrote it as a literal for brevity
let ownProps = []
for (prop in canary)
if (canary.hasOwnProperty(prop) { ownProps.push(prop) };
When I write up this exercise and execute it with Node, it works just fine. However, for FCC’s tests, it only works if declare the prop value first, like so:
for (let prop in canary) // using let keyword before prop
Was wondering if not declaring prop in the loop is a syntax error, and if so, why doesn’t Node complain about the error?