2

In the function, running normally, this displays "Hello world":

function fn () {
    function b1 () {}
    var b1 = 'Hello world';
    console.log(b1);
}
fn();

At the block statement, get an error: Uncaught SyntaxError: Identifier 'b1' has already been declared

function fn () {
     if (true) {
         function b1 () {};
         var b1 = 'Hello world';
         console.log(b1);
    }
}
fn();

So there is clearly something "special" about a block statement with respect to function declarations. why?

  • 1
    does this answer your question https://stackoverflow.com/questions/49774769/javascript-uncaught-syntaxerror-identifier-has-already-been-declared – First dev May 14 '21 at 01:47

0 Answers0