0

So since ES6 all functions are block scoped in strict mode, but "var" ignores block scope, then why code below gives a reference error?

'use strict'
function asd() {
  var ssss = 5;
}

console.log(ssss);
//reference error

for (const item of arr) {
  var sss = 5;
}

console.log(sss);
//5
  • 3
    `var ssss` is scoped to only the `asd()` function. – VLAZ Mar 21 '21 at 15:24
  • 2
    "*since ES6 all functions are block scoped*" that's not true - ES6 introduces block scope but functions aren't "block scoped" - function scope still exists. – VLAZ Mar 21 '21 at 15:25

0 Answers0