1、
There are a = 123;
function fun(){
alert(a) //123
}
fun()
2、
There are a = 123;
function fun(){
alert (a); // undefined, scope: should visit at this time a statement in the function of a, but variable declaration in two steps: Create a + variables are initialized variable (initialized to undefined) is then assigned. So, here
Output undefined (there is also a problem of variable lift inside)
There are a = 456;
}
fun()
alert(a) //123
3、
There are a = 123;
function fun(){
alert (a); // 123 is a variable declared functions not found in the question, so look for the outer layer to find the global declaration var a = 123, then the function is called, the output 123
a=456;
}
fun()
alert(a) //456
4、
There are a = 123;
function fun(a){
alert (a); // undefined parameters did not pass
a=456;
}
fun();
alert(a) //123
5、
There are a = 123;
function fun(a){
alert (a); // 123 after the transfer step as reference questions coming 3
a=456;
}
fun(123)
alert(a) //123
6、
There are a = 12;
function fn(){
console . log(a) //undefined
There are a = 45;
console . log(a) //45
}
fn()
7、
There are a = 12;
function fn(){
console . log(a) //12
a=45;
console . log(a) //45
}
fn()
8、
function fn(){
console . log(11)
function ff(){
console . log(22)
}
ff() //22
}
fn() //11
9、
There are a = 12;
function fn(){
console . log(a) //undefined 同题2
return 4;
There are a = 45;
}
fn()
10、
There are a = 45;
function fn(a){
console. log (a) // undefined parameters did not pass
}
fn()
11、
console . log(total); //undefined
was total = 0;
function fn(num1,num2){
console . log(total); //undefined 同题2
was total + = num1 num2;
console . log(total) //300
}
fn(100,200)
console. log (total) // 0 is global total
12、
console . log(to) //undefined
var to = 1;
function fn(n1,n2){
console . log(to) //1
to = n1 + n2;
console . log(to) //30
}
fn(10,20)
console . log(to) //30
13、
function fn(a){
console . log(a) //function
There are a = 123;
console . log(a) //123
function a(){ }
console . log(a) //123
was b = function () {}
console . log(b) //function
function b(){ }
}
fn(1)
Note: If we have to declare variables and functions of the same name, and in the pre-explain statement only once when
14、
function test(a,b){
console . log(b) //function
console . log(a) //1
c=0;
a=3;
b=2;
console . log(b); //2
function b(){ }
function d(){ }
console . log(b) //2
}
test(1)
15、
fun