2 basic js questions

Question 1
function bar(){
    //....
}

in chrome environment:

console.log(this.bar)//bar
console.log(window.bar)//bar

so you can think of bar as bound to window.

< hr >

so:
in node environment:

console.log(this.bar)//undefined
console.log(global.bar)//undefined

what is bar bound to at this time?

Question 2
var obj = {};
console.log(obj.a)//undefined

normally, obj.an is not defined. should be reported here.
actually executing this code here gives obj an attribute of an and assigns the value to undefined.

I read this in a book, and suddenly I don"t remember the answer.
I remember that this is the bug, of an object, so it has to be handled this way.

here I want to know what this bug is

Mar.11,2021
Let's not talk about

Node.js, which is well answered. It is called window, under CHROME and global under node.js.
in JS, undefined and undeclared are two different things. If a variable has been declared but has not been assigned, it is "undefined" and a variable is called without declaration, then it is "undeclared".
generally speaking, the error: referenceError: xx is not defined will mislead people to think that the variable is undefined, but it is actually more accurate to say that it is undeclared.
and both undefined and undeclared,typeof are handled by returning undefined


for the second question, I tested it under Chrome, and it looks as if obj does not have the attribute a

clipboard.png


,

2 undefined undeclared obj.a , obj.a.b 2

Google--js obj.a

Googlebug.

-
js obj.a obj.a is not defined ,
:


obj.a = 1 2 RHS(right-hand-side) obj.a1.
,


:JS


1

nodejsthismodules.exportsexports.bar = barexportsthis
globalnode


2

undefinedjavascripterror

objundefinedobj.aundefineda


nullundefined undefined


Question 1

clipboard.png

Question 2

normally undefined

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eb2a70-23f2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eb2a70-23f2.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?