es6基础入门变量的解构赋值
2024-08-29 09:55:42
let [a, b, c] = [1, 2, 3];
let [foo, [[bar], baz]] = [1, [[2], 3]];
foo //
bar //
baz // let [ , , third] = ["foo", "bar", "baz"];
third // "baz" let [x, , y] = [1, 2, 3];
x //
y // let [head, ...tail] = [1, 2, 3, 4];
head //
tail // [2, 3, 4] let [x, y, ...z] = ['a'];
x // "a"
y // undefined
z // []
// 报错
let [foo] = 1;
let [foo] = false;
let [foo] = NaN;
let [foo] = undefined;
let [foo] = null;
let [foo] = {};
let [x, y, z] = new Set(['a', 'b', 'c']);
x // "a"
let [foo = true] = [];
foo // true let [x, y = 'b'] = ['a']; // x='a', y='b'
let [x, y = 'b'] = ['a', undefined]; // x='a', y='b'
let [x = 1] = [undefined];
x // let [x = 1] = [null];
x // null
let [x = 1, y = x] = []; // x=1; y=1
let [x = 1, y = x] = [2]; // x=2; y=2
let [x = 1, y = x] = [1, 2]; // x=1; y=2
let [x = y, y = 1] = []; // ReferenceError
let { foo, bar } = { foo: "aaa", bar: "bbb" };
foo // "aaa"
bar // "bbb"
let { bar, foo } = { foo: "aaa", bar: "bbb" };
foo // "aaa"
bar // "bbb" let { baz } = { foo: "aaa", bar: "bbb" };
baz // undefined
var { foo: baz } = { foo: 'aaa', bar: 'bbb' };
baz // "aaa" let obj = { first: 'hello', last: 'world' };
let { first: f, last: l } = obj;
f // 'hello'
l // 'world'
let { foo: baz } = { foo: "aaa", bar: "bbb" };
baz // "aaa"
foo // error: foo is not defined
最新文章
- 用SQL命令查看Mysql数据库大小
- 黑马程序员----java基础笔记中(毕向东)
- Ueditor的两种定制方式
- 关于VS2015找不到WIN32的解决办法
- 设计包含min函数的栈
- 【Linux】鸟哥的Linux私房菜基础学习篇整理(九)
- (摘)Zebra打印机异常处理
- 深入理解PreparedStatement和Statement
- C++容器在遍历时的删除问题
- weblogic的ejb远程调用
- fpga该驱动器调试dev_dbg 无输出
- 在windows server2003下安装Redmine
- js设置、获取、清除cookie
- 开源社交系统ThinkSNS+ V0.8.0 正式发布(一期功能版本)
- IIS发布 用户 \'IIS APPPOOL\\X\' 登录失败
- C/C++下调用matlab函数操作说明
- JCE安装使用报错
- nginx配置前端代理
- 使用 CODING 进行 Hexo 项目的持续集成
- C和C指针小记(三)-整型,char,枚举