我只是在TypeScript中开始编码。所以请原谅我的新手问题。什么时候应该在TypeScript中使用“var”,“let”和“const”
我有这样的方法:
public copyToDest() {
for (var i = 0; i < this.source.length; i++) {
var item = this.source[i];
if (item && item.isValid)
this.dest.push(item);
}
}
这是工作的罚款。安装重构工具后,我得到了2点建议:
- 变化
var i = 0;
到let i = 0;
- 变化
var item = ...
到const item = ...
是有我丢失有关正确使用var
,let
和任何规则const
?或者我应该忽略这些建议?
相关:[在TypeScript中,什么时候使用“let”,什么时候使用“const”?](https://stackoverflow.com/questions/38858743/in-typescript-when-do-you-use -let-and-when-do-you-use-const) – crashmstr