可以嵌套的解构赋值
var [ a,b,[ c, d ] ] = [ 1,2,[ 3, 4 ] ];
console.log(c);
console.log(d);
var a = 1;
var b = 2;
[a,b] = [b,a];
${ }中函数调用
function fn() {
return "曲小强"
}
var s = `this is ${ fn() }`
console.log(s)
repeat( )函数将目标字符串重复N次,返回一个新的字符串
var oldName = "你好";
var newName = oldName.repeat(4);
console.log(oldName);
console.log(newName);
includes() 函数判断字符串中是否含有指定的子字符串,返回Boolean
var str = "百香果红茶";
str.includes('红');
Math.trunc函数:用于去除一个数的小数部分,返回整数部分。
Math.trunc(2.312313213);
Math.sign函数:用来判断一个数到底是正数、负数、零
Math.sign(22);
Math.sign(-22);
Math.sign(0);
Math.sign('aaa');
Array.from函数将字符串转换成数组
var str = 'Hello';
Array.from(str);
Object.assign()函数-合并对象
let a = {"a":1};
let b = {"b":2,"c":3};
Object.assign(a, b);
console.log(a);
参数的默认值
function person(name = '张三',age = 25){
console.log(name, age);
}
person();
person('李四',18);