JS face great integration questions

JS face great integration questions:

  1, JS in var, let, const What is the difference:

In the early js, use the var keyword to create a variable 

let the const keyword and is introduced ES6 version, which aims to create two different types of changes in js, one is variable, and the other is immutable.


let: variable used to create a variable, not the let repeat a statement of the same variable, suitable for use in the let for (let i = 0; i <xxx, i ++) cycle can be free from outside influence

const: used to create an immutable variables, variables are immutable throughout the lifetime of the program will not change its value

var: efficient global variables created, let the variables created only valid in the current code block

for example 1: and let the difference between var
{ 
  var i = 9;
 let x = 9; } console.log(i); // 9
console.log(x); // 报错:Uncaught ReferenceError: i is not defined

举个例子2:let不能重复声明同一个变量
A = 0 the let; 
the let A = 2;

the console.log (A); // being given
 
 





 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

//

Guess you like

Origin www.cnblogs.com/spll/p/11670301.html