LOGBOOK

HELP

Quiz Entry - updated: 2026.06.20

What happens when you access an array index or object property that doesn't exist?

You get the value undefined rather than an error — which is convenient but can quietly hide bugs.

JavaScript is forgiving here: reading a missing array slot or a non-existent object property doesn't crash your program. It simply yields the special value undefined:

let arr = ['a', 'b', 'c'];
console.log(arr[10]);   // undefined — index 10 doesn't exist, but no error

let obj = { name: 'John' };
console.log(obj.age);   // undefined — there's no 'age' property

The gotcha is that this silence hides mistakes: a typo'd property name returns undefined instead of complaining, and that undefined then drifts into the rest of your code, where it can cause a confusing failure far from the real cause.

So when a value might be missing, check for it explicitly:

if (obj.age !== undefined) {
    // the property exists and has a value
}

// For objects, the 'in' operator asks whether a key exists at all:
if ('age' in obj) {
    // the property exists (even if its value is undefined)
}

A broader fix many teams adopt is TypeScript, a typed layer on top of JavaScript that flags many of these missing-property mistakes at compile time, before the code ever runs.

From Quiz: WEBT / Introduction to JavaScript | Updated: Jun 20, 2026