spread Operator

Run Settings
LanguageJavaScript
Language Version
Run Command
function print(...a) { console.log(a); // print an values in the form of array, eg: [1,2,3] } function print1(a, b, c) { console.log(a, b, c); // print an values eg: 1 2 3 } let z = [1,2,3]; print(...z); print1(...z); function print2(...z){ console.log(z) } print2(1,2,3); // without declaring a new variable just pass the values into the function itself. You can add as many as arguments to it. // We have a function 'butter'. Right now it only returns the array 'a', [1, 2, 3]; // Later on, we call, butter(4, 5, 6). But instead of [1, 2, 3], we want butter to return [1, 2, 3, 4, 5, 6]; // How can we take advantage of the spread operator to make butter simply return [1, 2, 3, 4, 5, 6]? function butter(...z) { let a = [1, 2, 3, ...z]; console.log(a); } butter(4, 5, 6);
Editor Settings
Theme
Key bindings
Full width
Lines