<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>js 序列赋值</title> </head> <body> <script> /*序列赋值:同时给 2 个及以上变量赋值。 序列赋值情况: 1.完全赋值,变量和值一一对应。 2.赋空值,undefined。 3.不完全赋值,有的有值,有的 undefined。 * */ // 1.声明多个变量,并进行序列赋值。 let [a, b, c, d] = [1, 2, 3, 4]; console.log(...[a, b, c, d]); // 1 2 3 4 console.log(a, b, c, d); // 1 2 3 4 // 2.赋空值。 console.log("\n2."); [a, b, c, d] = []; console.log(a, b, c, d); // undefined undefined undefined undefined // 3.不完全赋值。 console.log("\n3."); [a, b, c, d] = [1, 2]; console.log(a, b, c, d); // 1 2 undefined undefined </script> </body> </html>
js 序列赋值.html
于 2018-12-25 20:07:04 首次发布