ES6新增

1.有关变量
参考学习:https://www.cnblogs.com/LLLLily/p/7389652.html

1.const定义的变量不可以修改,而且必须初始化
ES6引入的第三个声明类关键词:const 用来定义常量。
2.var定义的变量可以修改,如果不初始化会输出undefined,不会报错。
3.let是块级作用域,函数内部使用let定义后,对函数外部无影响。

ES6的let变量声明特点:

拥有块级作用域
没有变量声明提升
暂时性死区
不能重复声明
let不会成为全局对象的属性

以上let所介绍的规则均适用于const命令,不同的是,const声明的变量不能重新赋值,也是由于这个规则,const变量声明时必须初始化,不能留到以后赋值

2.解构赋值

https://www.cnblogs.com/xiaohuochai/p/7243166.html

对象解构:

   1.变量声明应用到对象解构
   2.变量赋值应用到对象解构
   3.解构赋值表达式的值与表达式右侧(也就是=右侧)的值相等
   4.解构赋值表达式时,如果指定的局部变量名称在对象中不存在,那么这个局部变量会被赋值为undefined
   5.当指定的属性不存在时,可以随意定义一个默认值,在属性名称后添加一个等号(=)和相应的默认值即可
   6.为非同名局部变量赋值
   7.嵌套对象解构
   8.嵌套对象解构非同名局部变量赋值

1.变量声明应用到变量解构

let node = {
    type: "Identifier",
    name: "foo"
};
let { type, name } = node;
console.log(type); // "Identifier"
console.log(name); // "foo"

2.变量赋值应用到变量解构

  let node = {
    type: "Identifier",
    name: "foo"
},
type = "Literal",
name = 5;
// 使用解构来分配不同的值
({ type, name } = node);
console.log(type); // "Identifier"
console.log(name); // "foo"

3.解构赋值表达式的值与表达式右侧(也就是=右侧)的值相等

let node = {
    type: "Identifier",
    name: "foo"
},
type = "Literal",
name = 5;
function outputInfo(value) {
    console.log(value === node); // true
}
outputInfo({ type, name } = node);
console.log(type); // "Identifier"
console.log(name); // "foo"

4.解构赋值表达式时,如果指定的局部变量名称在对象中不存在,那么这个局部变量会被赋值为undefined

let node = {
    type: "Identifier",
    name: "foo"
};
let { type, name, value } = node;
console.log(type); // "Identifier"
console.log(name); // "foo"
console.log(value); // undefined

5.当指定的属性不存在时,可以随意定义一个默认值,在属性名称后添加一个等号(=)和相应的默认值即可

let node = {
    type: "Identifier",
    name: "foo"
};
let { type, name, value = true } = node;
console.log(type); // "Identifier"
console.log(name); // "foo"
console.log(value); // true

6.为非同名局部变量赋值

let node = {
    type: "Identifier",
    name: "foo"
};
let { type: localType, name: localName } = node;
console.log(localType); // "Identifier"
console.log(localName); // "foo"

7.嵌套对象解构

let node = {
    type: "Identifier",
    name: "foo",
    loc: {
        start: {
            line: 1,
            column: 1
        },
    end: {
        line: 1,
        column: 4
    }
}
};
let { loc: { start }} = node;
console.log(start.line); // 1
console.log(start.column); // 1

8.嵌套对象解构非同名局部变量赋值

let node = {
    type: "Identifier",
    name: "foo",
    loc: {
        start: {
            line: 1,
            column: 1
        },
        end: {
            line: 1,
            column: 4
        }
    }
};
// 提取 node.loc.start
let { loc: { start: localStart }} = node;
console.log(localStart.line); // 1
console.log(localStart.column); // 1

数组解构:

3.箭头函数·
1.基础语法·
2.高级语法
3.更短的函数
4.不绑定this
5.与严格模式的关系
6.通过·call,apply调用
7.不绑定arguments
8.像函数一样使用箭头函数
9.使用 new 操作符
10.使用prototype属性
11.使用 yield 关键字
4.类和面向对象

5.字符串和变量的拼接

单行字符串与变量的拼接
多行字符串的拼接

猜你喜欢

转载自blog.csdn.net/weixin_41989325/article/details/89424922