Javascript local and global variable confusion [duplicate]
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This question already has an answer here: How do JavaScript closures work? 88 answers Variable: local scope, global scope or is it the JavaScript engine? 3 answers I am new to JavaScript and I was doing some practices on local and global variable scopes, following is my code( fiddle ): var myname = "initial" function c(){ alert(myname); var myname = "changed"; alert(myname); } c(); when the first alert is called, it is showing myname as undefined. so my confusion is why I am not able to access a global instance of myname and if I don't