繁体   English   中英

为什么没有'var'关键字的变量不在chrome控制台的全局范围内?

[英]Why is a variable without the 'var' keyword not in the global scope in the chrome console?

因为我没有使用var关键字,为什么变量'local'不在chrome控制台的全局范围内?

function test(){
local = true;
};

console.log(local);//Uncaught ReferenceError: local is not defined

仅仅是因为从未调用过test函数,所以从未创建过局部变量,因此会引发错误

在此处输入图片说明

一旦调用test() ,它将可用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM