篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Const vs Let:ES6相关的知识,希望对你有一定的参考价值。
let name = "Nick";
const tinyize = function (name) {
const myName = 'Tiny ' + name + '!';
return myName;
};
name = tinyize('Rick');
console.log(name);// Tiny Rick
for (let i = 0; i < 5; i++) {
setTimeout(function () {
console.log(i); // let = 0 let = 1, let = 2, let = 3, let = 4
}, 100);
}
console.log(i) //>>> THIS WILL create an ERROR, because LET is block scoped!! (vs Var that is instead scoped to the Lexical Feild).
以上是关于javascript Const vs Let:ES6的主要内容,如果未能解决你的问题,请参考以下文章