as u can see below , obj.key outside the for in loop is working properly but why not in the for in loop ?
and obj[key] inside the for in loop is working properly , what`s the reason behind one is working correctly and other one is not ?
code
let obj = {
name: "lucky",
hobbies: "coding"
}
console.log(obj.name)
for (let key in obj) {
console.log(obj.key)
}
output
lucky
undefined
undefined