Why a variable defined global is undefined? [duplicate]
问题 This question already has answers here : 'Hoisted' JavaScript Variables (3 answers) Closed 4 years ago . Hi guys here I have a simple function and a global variable. Why is myname undefined and not the string \"global\" ? var myname = \"global\"; // global variable function func() { alert(myname); // \"undefined\" var myname = \"local\"; alert(myname); // \"local\" } func(); Is not possible to refer to a outer variable that is define outside the scope of that function? and in this a global