关于JavaScript中的作用域概念
发布时间
阅读量:
阅读量
在JavaScript语言中,作用域指的是变量和函数的可达范围。主要分为两大类:一种是函数级别的作用域,另一种是块状的作用域。
- 函数作用域:
我们称它们为function scope,并是在此范围内声明变量与功能单元。这些internal variables and functions仅限于在function scope内部进行调用或引用。outside of a function scope, these variables and functions是不可用的.主要源于使用var关键字声明variables and functions within a function scope.
function exampleFunction() {
var localVar = "I'm a local variable";
console.log(localVar); // 输出 "I'm a local variable"
}
exampleFunction();
console.log(localVar); // 报错:ReferenceError: localVar is not defined
AI写代码javascript
运
全部评论 (0)
还没有任何评论哟~
