How to understand this piece of JS code?

I saw this code when I was looking at ES6. I don"t quite understand this code. I don"t know about scope.

related codes
{
    function fooc() { return 1 }
    {
        function fooc() { return 3 }
    }
    console.log(fooc())
}
console.log(fooc())

//
1
3
Why not all 3, or why not all 1?
Sep.16,2021

you are looking at the block-level scope of ES6. A single pair of curly braces will generate a block-level scope, and the function will be promoted to the top of the current scope

.

= the above is a simple answer to see the question using the mobile phone =

use the computer to test the results

clipboard.png

,

: ECMAScript 6

ES6

babel

clipboard.png

node1

clipboard.png

clipboard.png

Menu