TypeError: updating let error in Firebug console when running ES6 code

I am learning ES6, so please carry me.

Below is the code that works fine if I press the start button once, but on the second hit it starts showing a TypeError: redeclaration of let myArr .

Let me know about this weird (maybe not) behavior.

 let myArr = [34,45,67,2,67,1,5,90]; let evenArr = []; let oddArr = []; myArr.forEach(x => { if (x % 2 === 0) { evenArr.push(x); } else { oddArr.push(x); } }); console.log(evenArr); console.log(oddArr); 

Error -

redelaration of let error

+5
source share
1 answer

ES6 does not allow you to do this (overriding a variable with a block scope in the same scope):

 let foo; let foo; 

And since the console retains state until you reload the page (after all, you are in the context of the page), the first time you define myArr , so you cannot redefine it in the second run.

+7
source

Source: https://habr.com/ru/post/1246391/


All Articles