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,