Why is 'undefined' being logged when i try to access an object property?

If you're getting `undefined` when trying to access an object property, it might be because the property doesn't exist in the object. Example:

let person = {name: 'John', age: 25};
console.log(person.salary);
Solution:

if ('salary' in person) {
    console.log(person.salary);
} else {
    console.log('Salary not defined');
}
Use the `in` operator to check if a property exists in an object before accessing it.

Beginner's Guide to JavaScript