Can be nested destruct assignment

var [ a,b,[ c, d ] ] = [ 1.2[3.4]].console.log(c);// Result: c = 3
console.log(d);// result: d = 4

var a = 1;
var b = 2;
[a,b] = [b,a];
Copy the code

Function call in ${}

function fn() {
    return "Qu Xiaoqiang"
}
var s = `this is ${ fn() }`
console.log(s) // This is a song xiaoqiang
Copy the code

The repeat() function repeats the target string N times, returning a new string

// repeat() repeats the target string N times, returning a new string
var oldName = "Hello";
var newName =  oldName.repeat(4);
console.log(oldName); // Result: Hello
console.log(newName); // Result: Hello hello hello hello hello
Copy the code

The includes() function determines whether the string contains the specified substring, returning a Boolean

var str = Passion Fruit Black tea;    // Target string
str.includes('red'); // true
Copy the code

Math.trunc: Removes the decimal part of a number and returns the integer part.

Math.trunc(2.312313213);
2 / / results
Copy the code

Math.sign: determines whether a number is positive, negative, or zero

Math.sign(22); // Result: 1
Math.sign(-22); // Result: -1
Math.sign(0); // Result: 0
Math.sign('aaa'); // NaN
Copy the code

The array. from function converts a string to an Array

var str = 'Hello';
Array.from(str);
// Result: ["H", "e", "l", "l", "o"]
Copy the code

The object.assign () function – merges objects

let a = {"a":1};

// This acts as the source object
let b = {"b":2."c":3};

Object.assign(a, b);

// Print the target object to see
console.log(a);
{a: 1, b: 2, c: 3}
Copy the code

The default value of the parameter

function person(name = 'Joe',age = 25){
   console.log(name, age);
}

person(); // Result: Zhangsan 25
person('bill'.18); // Result: Lisi 18
// Default parameters cannot be followed by parameters that do not need default values.
Function person(age = 25,name){}
Function person(name,age = 25){}
Copy the code