es6常用功能

  1. let/const
  2. 多行字符串/模板变量
    • const name = 'kelly', age = 18;
      const html = `<div>
                      <p>name: ${name}</p>
                       <p>age: ${age}</p>
                    </div>`          
  3. 解构赋值
    • const obj = {a:10,b:20,c:30}
      const {a,c} = obj
      console.log(a) //10
      console.log(c) //30

      const arr = ['xxx','yyyy','zzz']
      const [x,y,z] = arr
      console.log(x) //xxx
      console.log(z) //zzz
  4. 块级作用域
  5. 函数默认参数
    • function (a, b=0) {
      }
      // 如果不参数b, 默认b为0
  6. 箭头函数
    • const arr = [1,2,3]
      // 如果函数只有1个参数,并且函数体只有1行代码
      arr.map(item => item + 1);
      
      // 如果函数有多个参数、函数体有多行代码
      arr.map((item, index) => {
        console.log(index)
        return item + 1
      })
原文地址:https://www.cnblogs.com/kelly07/p/8695298.html