Talking about the development of variable scope --- pits

The recent development encountered a small problem, do not pay more attention to when looking for some other way only temporarily, under her spare time looked so simple ... ... here prepared to leave a record.

var x = 1;
function fn(x){
  console.log(x)
};
fn()

The output is undefined, reasons: the local variable x covered global variables.

var x = 1;
function fn(){
  console.log(x)
};
fn()

The output is 1

Then use the arrow functions, so do not quickly locate the error ... ... it is not enough Daoxing ah, continue to fuel

 

 

 

 

 

.

Guess you like

Origin www.cnblogs.com/jianxian/p/12529533.html