variable statment(变量语句)

A variable statement declares variables that are created as defined in 10.5. Variables are initialised to undefined when created. A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed, not when the variable is created.

 

这里很很重要的一句:

A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed, not when the variable is created.
可见,如 var a=5;这种形式的语句是分两步进行的:

 

第一步,创建 variable a, 保证变量的存在

第二步,执行,对变量a赋值

 

如果像这样

var a=1 ;

var b=2;

var c=3;

则是:

第一步 ,创建变量a,b,c,此时他们的值都是undefined

第二部,对 a,b,c 分别赋值

 

注意:

只有当执行上下文(execution context)建立后才会进行上面的两步。

 

相关文章:

  • 2021-11-06
  • 2022-03-07
  • 2021-09-15
  • 2021-07-20
  • 2022-02-15
  • 2021-06-25
猜你喜欢
  • 2021-10-24
  • 2022-12-23
  • 2021-08-25
  • 2021-07-23
  • 2021-12-23
  • 2022-12-23
  • 2022-01-10
相关资源
相似解决方案