- 变量声明
let、const
let 声明的变量具有块级作用域,不可重复定义
const 声明的变量为常量,不可变,具有块级作用域
let num = 1;
let num = 2;
****************
Uncaught SyntaxError: redeclaration of const str
****************
const str = "hello";
str = "hello world";
****************
Uncaught TypeError: invalid assignment to const 'str'
****************
const arr = [1,2,3];
let [a,b,c] = arr;
console.log(a,b,c);
******************
1 2 3
******************
const json = {
id:1,
name: 'xiaoli',
age: 23
};
let {
name,age:myAge} = json;
console.log("name:",name)
console.log("age:",myAge)
******************
name: xiaoli
age: 23
******************
const arr = [{
id:1,name: 'xiaoli',age: 23}];
const