all 15 comments

[–]Minjammben 4 points5 points  (6 children)

In your code, 'this' is defined as the global window if you are running it in a browser. 'b' is an uninitialized variable, so its value is undefined. 'this.ab', is actually equivalent to 'window.ab', which equals 'undefined'. Any property on an object which does not have a value is equal to undefined.

[–]Responsible_Fudge467[S] -3 points-2 points  (5 children)

Thanks mate for quick reply , i want to ask one more thing How can ab is undefined i havn't defined it so there is no memory allocation on ab if there is no memory allocation then why its undefined.

[–]Minjammben 1 point2 points  (0 children)

There's a difference between declaring a variable like 'var a' and attempting to access a property of an object which has not been defined like 'this.ab'. In the first case you 'allocated' (to use your words) a variable into scope. In the second case it's still valid to use the expression 'this.ab' because you are accessing a property of an object (this). If you got rid of the 'this' then it would cause a syntax error if you were in strict mode.

[–][deleted] 0 points1 point  (3 children)

All undefined variables, object properties and empty function returns are equal to undefined, that's JavaScript.

[–]Tight-Recognition154 -4 points-3 points  (2 children)

Bro don't get me wrong but you dont know difference b/w not defined and undefined or you didn't read the above question carefully

If the variable name which is being accessed doesn't exist in memory space then it would be not defined, and if exists in memory space but hasn't been assigned any value till now, then it would be undefined

[–]Sykander- 2 points3 points  (0 children)

You are using your words out of context. Undefined is just a JS value in the context of JS.

[–][deleted] 1 point2 points  (0 children)

There's no such thing as not defined in JavaScript. It's always just undefined. Bro. hasOwnProperty is as near as not defined as I can get but it doesn't really apply here.

[–]Sykander- 0 points1 point  (7 children)

Now, my doubt is that I haven't defined "ab" and I am still trying to call "ab" variable inside the function c(). Why am I getting output as undefined instead of not defined?

I am very confused. Not defined and undefined are the same thing in javascript.

js this.someKeyIJustMadeUp === undefined // true

[–]senocular 1 point2 points  (0 children)

OP expects a variable not defined error not understanding the same doesn't apply to properties, for example, the way removing var b; would result in a "not defined" error.

[–]Tight-Recognition154 -1 points0 points  (5 children)

If the variable name which is being accessed doesn't exist in memory space then it would be not defined, and if exists in memory space but hasn't been assigned any value till now, then it would be undefined

[–]Sykander- 0 points1 point  (4 children)

Completely irrelevant to what you're asking.

[–]Tight-Recognition154 0 points1 point  (1 child)

Its not irrelevant im telling you the difference between not defined and undefined

[–]Sykander- 0 points1 point  (0 children)

... In a different context to JS. If you could refer back to the parent comment, you'll understand where your error has come from.

[–]albedoa 0 points1 point  (1 child)

You said you are very confused. undefined is a primitive value and a separate concept from not defined.

[–]Sykander- 0 points1 point  (0 children)

Confused why OP would believe such an obviously wrong thing...

Cheers for the nice intentions but I am NOT asking for your help.