Work is bitter is sweet, enrich their perseverance

< span style = “max-width: 100%; clear: both; min-width: 100%;

         // var a = '?? '
        const  a = '76wenshu';
        function wenshu(){
            const b="??????"
            debugger
            // call stack wenshu
            console.log(a)
            console.log(b)

            // var a = 'fire in heart, light in eye'
            // Call location
            this.light()
            // console.log(Local);
            console.log(this)
            console.log(this.a)
            debugger
        }
        function light(){
            // call stack wenshu -> light
            console.log(this.a)
        }
        // Call location
        wenshu()
Copy the code

See this moment in the circle?? Question marks… What the hell? What’s going on?

//var declares an A under window

I called the debugger in there…

I didn’t find the a I declared in the window in Script scope

// This section covers the scope and object content will be written later

[[scope]]: all JS functions are objects. Some properties of objects can be accessed by us, but some properties can not be accessed by the JS engine. [[scope]] is one of these properties. [[scope]] refers to what we call a scope, which stores a collection of run-time contexts. That is, scope determines the visibility of variables and other resources in a code block.

So that’s another question that comes up: How do we refer to the outside variable A, since it’s not under the window

Console. log(a)//76wenshu

The global declaration of const and let is placed in the block-level scope of a particular Script, so the function declared inside can use the variable A directly.

Personal curiosity: declare another B in the function

B also sees Script in function scope, in function scPOes

Remember that const and let variables declared globally are not under Windows