Destructuring:
Destructuring is to take the array, object, and variable and make it into a smaller one.
function sumAndMultiply(a, b) {return [a + b, a * b];}const [sum, multiply] = sumAndMultiply(3, 4);console.log(sum);// Result: 7console.log(multiply);// Result: 12
function sumAndMultiply(a, b) {return [a + b, a * b, a / b];}const [sum, multiply, division = "no division"] = sumAndMultiply(3, 4);console.log(sum);// Result: 7console.log(multiply);// Result: 12console.log(division);// Result: 0.75
Post a Comment