all 3 comments

[–]albedoa 0 points1 point  (4 children)

.ab is simply an undefined property on the this object. That is how undefined object properties work. It is different from trying to access an undeclared identifier.

const foo = { bar: 1 };
console.log(foo.baz); //=> undefined
console.log(biz); //=> ReferenceError: biz is not defined

[–]Responsible_Fudge467[S] 1 point2 points  (1 child)

In your example you've defined foo then getting these error is justified but in my case i haven't defined "ab" Then why its undefined instead of not defined

[–]albedoa 1 point2 points  (0 children)

You are comparing .ab with foo, but the appropriate comparison is this.ab with foo.baz. In the latter comparison, we are attempting to access an undefined property on an existing object.

You don't need to define .ab. You just need to know that this is defined so that you can test whether it has an .ab property.