let和const命令 let定義變量 const定義常量,不推薦用于定義對(duì)象 先定義后使用;因?yàn)椴淮嬖谧兞刻嵘駝t報(bào)錯(cuò),產(chǎn)生暫時(shí)性死區(qū)。 const a = 1; console.log(a); 在對(duì)應(yīng)的塊級(jí)作用域下使用 { let a =1; console.log(a); } 不允許重復(fù)定義 6種定義變量的方式var,function,let,const,import,class 變量的解構(gòu)賦值 允許按照一定模式,從數(shù)組和對(duì)象中提取值,對(duì)變量進(jìn)行賦值,這被稱為解構(gòu),如: var [a, b, c] = [1, 2, 3]; let [ , , third] = ["foo", "bar", "baz"]; third // "baz" let [x, , y] = [1, 2, 3]; x // 1 y // 3 let [head, ...tail] = [1, 2, 3, 4]; head // 1 tail // [2, 3, 4] let [x, y, ...z] = ['a']; x // "a" y // undefined z // [] 用途 交換變量的值 從函數(shù)返回多個(gè)值 函數(shù)參數(shù)的定義 提取JSON數(shù)據(jù) 函數(shù)參數(shù)的默認(rèn)值 遍歷Map結(jié)構(gòu) 輸入模塊的指定方法 const { SourceMapConsumer, SourceNode } = require("source-map");