“Parameter REST JavaScript vs Operator Spread” Kode Jawaban

Parameter REST JavaScript vs Operator Spread

/** 
* JS Spread and Rest operators:
* Two operators with the same syntax (...) but behave differently
*/

// Rest parameter: collects all remaining elements into an array. 
function foo (...args) { console.log(args) } 
foo(1,2,3,4,5,6) // Output: (6) [1,2,3,4,5,6]

// Spread operator: allows iterables to be expanded into single elements.
let arr = [1, 2, 3];
let arrCopy = [-1, 0, ...arr]; // spread the array into a list of parameters
                        // then put the result into a new array
GitPaulo

menyebar dan istirahat operator javascript

var myName = ["Marina" , "Magdy" , "Shafiq"] ;const [firstName , ...familyName] = myName ;console.log(firstName); // Marina ;console.log(familyName); // [ "Magdy" , "Shafiq"] ;
Relieved Rook

Jawaban yang mirip dengan “Parameter REST JavaScript vs Operator Spread”

Pertanyaan yang mirip dengan “Parameter REST JavaScript vs Operator Spread”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya