• ES6__变量的解构赋值


    /*
     变量的解构赋值
    */
    
    /*
    基本概念 :
        本质上就是一种匹配模式,只要等号两边的模式相同,那么左边的变量就可以被赋予对应的值。
    结构赋值主要分为:
    1. 数组的解构赋值
    2. 对象的结构赋值
    3. 基本类型的结构赋值
    */
    //1. 数组的解构赋值
    // let a = 1;
    // let b = 2;
    // let c = 3;
    // let [a,b,c] = [1,2,3];
    // console.log(a,b,c)   1 2 3
    
    // let [a,[[b],c]] = [1,[[2],3]];
    // console.log(a,b,c); // 1 2 3
    
    //let [,,c] = [1,2,3];
    //console.log(c) //3
    
    // let [x] = [];
    // console.log(x); //let x; undefind
    
    // let [y = 1] = [];   默认值
    // console.log(y); // 1
    
    
    //2.对象的解构赋值
    // let {a,b} = {b:'bbb',a:'aaa'};
    // console.log(a,b)
    
    // let {a:b} = {a:1};
    // console.log(b); 1
    // console.log(a);  undefind
    
    //3.基本类型的解构赋值
    // let [a,b,c,d] = '1234';
    // console.log(a,b,c,d); // 1 2 3 4
    
    // let {length:len} = 'mingxiao';
    // console.log(len); // 8 
    
    // let {toString:ts} = 1;
    // let {toString:bs} = true;
    // console.log(ts === Number.prototype.toString); // true
    // console.log(bs === Boolean.prototype.toString); //true
    
    // null 和 undefind  不能进行解构赋值
    // let [a] = null;
  • 相关阅读:
    EcFinal游记
    简要介绍补码的原理
    【SCOI2007】降雨量
    【ecfinal2019热身赛】B题
    【HAOI2011】problem a
    20200301(ABC)题解 by李旭晨
    20200228(ABC)题解 by 马鸿儒
    20200220(C)题解 b刘存
    20200225(DEF)题解 by 马鸿儒
    20200224(ABC)题解 by 马鸿儒
  • 原文地址:https://www.cnblogs.com/xiaozhishang/p/8759585.html
Copyright © 2020-2023  润新知