Distinction var, let, const three

1, a block-level scope {}

ES5 in scope are: global scope, function scope.

ES6 new block-level scope. Includes a block-level scope} {, if statements, and for statement {} block also belongs to the scope

 

2 distinction, var, let, const of

  1. var variable definition, there is no concept of a block, across the block access can not access across function
  2. let-defined variables can only be accessed in block scope, can not cross block access, access can not be cross-function
  3. const is used to define the constants, it must be initialized using only accessible in scope and can not be modified block

 

3, const object attribute is defined may vary

can.

Reference type of object, the saved person is only an object pointer, which means, const pointer only to ensure that does not change, modify the properties of an object does not change the pointer to the object, it is allowed.

Const reference type that is defined as long as the pointer is not changed, other changes are allowed.

Guess you like

Origin www.cnblogs.com/knightdreams6/p/11859275.html