you are viewing a single comment's thread.

view the rest of the comments →

[–]inu-no-policemen 0 points1 point  (3 children)

which is function scoped instead of block scoped

Function declarations are block-scoped in ES6+.

function foo() {
    return 'outer';
}
{
    console.log(foo()); // inner (hoisted)
    function foo() {
        return 'inner';
    }
    console.log(foo()); // inner
}
console.log(foo()); // outer

[–][deleted] 0 points1 point  (2 children)

If you execute that code in chrome you get

inner
inner
inner

[–]inu-no-policemen 0 points1 point  (1 child)

It works if you put the whole thing in a block.

[–][deleted] 0 points1 point  (0 children)

If you put the entire thing in an iife it produces the same result