The original link, explain in more detail: www.yuque.com/yw8upm/gr7b…

If you take a look at this, what do you think it’s going to print?

Don’t think about just copying and pasting it into the browser

The answer is

1,undefined, funtion arg(){}
2,undefined
3,108
4Undefind,5I am bear big, age77
6I am bear big, age188
7I am bear big, age88
Copy the code

According to? Listen to me

Article 1 Demo (18) is triggeredconsole.log(obj1, arg)

Undefined, funtion arg(){}

  • Obj1 >>> undefined this is probably something most of you know about, because of the variable elevation of the function
  • arg >>> functionWhy is that? Why not18

Here’s the first point: precompile

precompiled

Precompile occurs just before running the function demo

  • As a first step, you can create an AO (Activation Object) Object: this can be interpreted as a refrigerator for demo to use when executing internal code (variables, functions…)
  • The second step is to treat the parameter and variable declarations as AO property names with undefined values.
  • The third step is to unify the parameters with the arguments.
  • Fourth, look for the function declaration in the function body and assign the value to the function body.

The argument 18 is actually in step three. The fourth step is covered by the body of the function. So the first arG is function…

Article 2 Executionconsole.log(length)

The answer is undefined. I don’t need to talk about that.

Article 3 Executionconsole.log(length)No doubt about it

The answer to 108. The value length = 108 has already been assigned.

Article 4 Executionif(console.log("undefined") || ....

The answer is undefined, didn’t you think? The if criteria are also executed by the browser. Not only is it executable, but it doesn’t return a value. So this is the time to go back into the back or (!! ” + “1” && typeof typeof null && !! Length) and then perform a series of operations:

  • !!” “+ “1” >>> string FALSE1 (cast)
  • Typeof typeof NULL >>> typeof “object” >>> String

Article 5 ExecutionObj2. Say (Bald strong, 77)No doubt about it

The answer is big, 77. SetTimeout you wait!! Why not bald? Because say this is obj1.

Article 6 ExecutionPromise. Then: obj2. Say (baldheaded strong, age)

Article 7 ExecutionObj1. Say (xiong 3, 88)

Sixth and seventh, setTimeout vs. promise, that is, of course, the microtask promise.then is executed first.

The original link, explain in more detail: www.yuque.com/yw8upm/gr7b…