if(true) {
tmp = 'abc';
console.log(tmp);//which should throw referenceError but not
let tmp;
console.log(tmp);
tmp = 123;
console.log(tmp);
}
Этот код приводитПочему этот код не приводит к ReferenceError?
abc
undefined
123
Почему первый console.log (TMP) не выдаст ошибку?
why it should throw a referenceError
In ECMAScript 2015, let will hoist the variable to the top of the block. However, referencing the variable in the block before the variable declaration results in a ReferenceError. The variable is in a "temporal dead zone" from the start of the block until the declaration is processed.
проблема bable настройки, я думаю.
так, может быть, это ошибка babel? https://github.com/babel/babel.github.io/issues/826
Зачем это ошибка, если вы определили ее 'tmp = 'abc';' – Tushar
Ваше первоначальное использование 'tmp = 'abc'' неявно объявляет var. –
Пожалуйста, покажите нам настройки вашего Babel.Это определенно должно вызывать ошибку, хотя это может и не быть, если вы переводите в свободный режим. – Bergi