Home > front end >  JS problem, don't understand
JS problem, don't understand

Time:09-30

Why can tell me the principle of no, an error, can't wish?

CodePudding user response:

Finally understand: about statement in advance ~=statement with expression is the belt will be divided into two steps, first the name refers to the top, and then assign a value in the same spot, but the function c () the function declaration is only one step, declaration and assignment simultaneously, so the var c=1 assignment will be after the function assignment, so the final c is not a function, but is 1

CodePudding user response:

reference 1st floor weixin_42590033 response:
finally understand: about statement in advance ~=statement with expression is the belt will be divided into two steps, first the name refers to the top, and then assign a value in the same spot, but the function c () the function declaration is only one step, declaration and assignment simultaneously, so the var c=1 assignment will be after the function assignment, so finally c is not a function, but 1

Finally understand: about statement in advance ~=statement with expression is the belt will be divided into two steps, first the name refers to the top, and then assign a value in the same spot, but the function c () the function declaration is only one step, declaration and assignment can simultaneously ahead of schedule, so, var c=1 assignment will be after the function assignment, so the final c is not a function, but is 1

CodePudding user response:

JS the function name is the variable name,
So function and variable c c is the same,

CodePudding user response:

The
reference 3 floor sky waves reply:
JS the function name is the variable name,
So function and variable c c is the same,

I know this, because the JS is weakly typed language, I ask is the problem of variable declarations ascension

CodePudding user response:

Predefined, in front of the code are not performed will be a reference type data preview address stored in the stack, data is stored in the heap; Variables for value types are stored in the stack; Code from the top down, preview and the variable, then preview function method, after calling methods cannot judge is a variable or an error

CodePudding user response:

Predefined, in front of the code are not performed will be a reference type data preview address stored in the stack, data is stored in the heap; Variables for value types are stored in the stack; Code from the top down, preview and the variable, then preview function method, after calling methods cannot judge is a variable or an error

CodePudding user response:

refer to 6th floor Dust_SongYunfei response:
predefined, in front of the code are not performed will be a reference type data preview address stored in the stack, data is stored in the heap; Variables for value types are stored in the stack; Code from the top down, preview and the variable, then preview function method, in the calling method is unable to determine variables or or an error is

The beginning of the stack, the teacher is so speak but later discovered, originally a teacher first is a Java engineer, so use the concept of stack and heap, then a professional web front-end lecturer said, JavaScript inside there is no stack and heap, only Windows and Windows, and the Java heap and stack concepts are similar, but I mention this problem has now been understood, thank you for your great article

CodePudding user response:

The
refer to the original poster weixin_42590033 response:
can explain the principle of no, why the error, can't wish?

https://gitee.com/hflxhn/summary/blob/master/web/javascript/1%20-%20%E9%A2%84%E7%BC%96%E8%AF%91/2%20-%20%E9%A2%84%E7%BC%96%E8%AF%91%E6%A6%82%E5%BF%B5.html
You can take a look at this, js precompiled process
//1. Create AO Object Activation Object (execution context)
//2. Look for lines and variable declarations, variable and line name as AO attribute name, value of undefined
//3. The argument refers to the unity and line and
//4. Find a function declaration in the body of the function, value function body
//
The function fn (a) {
The console. The log (a);

Var a=123;
The console. The log (a);

Function a () {}

The console. The log (a);

Var b=function () {}

The console. The log (b);

The function d () {}
}
Fn (1);
//precompiled occurred before the function performs a moment
//
//AO {
//a: functiona () {}
//b: undefined
//d: function () {}
//}
  • Related