Home > front end >  Why JavaScript constructor incoming parameters can not do this assignment
Why JavaScript constructor incoming parameters can not do this assignment

Time:09-17

As shown in figure, bosses for

CodePudding user response:

The scope of the variable

You in the function that the var val=parseFloat (val). The second val here won't go to pick up the constructor to receive the value of the local variable val of val but take undefined

 
The function fn (val) {
Function a () {
Var val=val;
The console. The log (val)//undefined
}

(a)
}
Fn (1)

The function fn2 (val) {
Function a () {
Var val2=val;
The console. The log (val)//1
}

(a)
}
Fn2 (1)


CodePudding user response:

I don't care which line in the function definition var val he default are the first line to define variables so understanding about

CodePudding user response:

The Max and min are the two functions, the scope of the two functions are independent, not to get another scope of variables, if you want to all functions use val variable, can add in the outermost function enclosing val=val,

CodePudding user response:

The
authorization reference 2 floor? Authentication response:
I don't care which line in the function definition var val he default are the first line to define variables so understanding about

Scope of the variable ascension is this meaning, as long as it is within the scope defines the variables and then from the first line of the variable is doomed to be a local variable, to your assignment before are undefined

CodePudding user response:

reference code for the family's reply: 3/f
Max and min are two functions, the scope of the two functions are independent, not to get another scope of variables, if you want to all functions use val variable, can add in the outermost function enclosing val=val,

Thank you bosses

CodePudding user response:

reference wind 灬, 4/f, cloud response:
Quote: authorization reference 2 floor? Authentication response:

I don't care which line in the function definition var val he default are the first line to define variables so understanding about

Variable increase scope is this meaning, as long as it is within the scope defines the variable, then from the first line of the variable is doomed to be a local variable, to your assignment before are undefined

The points and how to pay
  • Related