no-var
NOTE: this rule is part of the
推荐 rule set.Enable full set in
deno.json:{
"lint": {
"rules": {
"tags": ["推荐"]
}
}
}Enable full set using the Deno CLI:
deno lint --rules-tags=推荐
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the
include or exclude array in deno.json:{
"lint": {
"rules": {
"include": ["no-var"],
"exclude": ["no-var"]
}
}
}强制使用块作用域变量,而不是更容易出错的函数作用域变量。块作用域变量使用 const 和 let 关键字定义。
const 和 let 关键字确保使用这些关键字定义的变量在其块作用域之外不可访问。另一方面,使用 var 关键字定义的变量仅限于其函数作用域。
无效:
var foo = "bar";
有效:
const foo = 1;
let bar = 2;