typescript Var,Let和const

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了typescript Var,Let和const相关的知识,希望对你有一定的参考价值。

var container = document.getElementById('container');

for (var x = 0; x <= 5; x++) {
    var counter = x;
    const counterConst = x;
    let counterLet = x;
    counter = 1;
}

console.log(counter);
console.log(counterConst); //Error
console.log(counterLet); //Error
//`var` is now the weakest signal available when you define a variable in JavaScript
//`const` is a signal that the identifier won’t be reassigned.
//`let`, is a signal that the variable may be reassigned, such as a counter in a loop, or a value swap in an algorithm. It also signals that the variable will be used only in the block it’s defined in, which is not always the entire containing function.

以上是关于typescript Var,Let和const的主要内容,如果未能解决你的问题,请参考以下文章

TypeScript的变量声明

LayaBox---TypeScript---变量声明

TypeScript 变量声明

第四章 变量声明

var,let和const的区别是什么?

js 中var contst let 之间的区别