Skip to content

wangyingjun/es6-note

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

es6-note

块级绑定

let const ###知识点:

  1. 块级作用域
    if(true){
        let test='test';   
    }
    console.log(test) // Error test is not defined
  2. 不会有变量提升
  3. 同作用域中相同变量名不可重复声明
  4. for循环中区块变量自动生成 (用const声明变量会报错)
    for(let i=0; i<10; i++){
        setTimeout(function(){
            console.log(i)
        },1000)
    }
    // 0 1 2 3 4 5 ...9
    
    //这并不是let本身的机制,而是语法规定中for循环中let声明每次循环都会创建一个
    //变量副本提供给函数
  5. for-in for-of 支持let const

###总结: 声明变量劲量用 const, 明确需要修改的用 let

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published