局部范围意味着变量在某个区域内可用。在本练习中, myVar仅在函数内可用,而不在外部。
myVar
以下是创建本地myVar变量的基本代码解决方案。
function myLocalScope() { var myVar; console.log(myVar); } myLocalScope();
该变量仅存在于函数中。在函数之外,它是不存在的。