Spread Operator Flashcards

1
Q
function sum(x, y, z) {
  return x + y + z;
}

const numbers = [1, 2, 3, 5];

console.log(sum(_________));

A

…numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
function sum(x, y, z) {
  return x + y + z;
}

const numbers = [1, 2, 3, 5];

console.log(sum(…numbers)); //

A

expected output: 6

only takes in x,y,z

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
function sum(x, y, z) {
  return x + y + z;
}

const numbers = [1, 2, 3];

console.log(sum(…numbers)); //

A

expected output: 6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

const numbers = [1, 2, 3];

console.log(…numbers)); //

A

1,2,3

numbers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

const numbers = [1, 2, 3];

console.log(numbers)); //

A

[1,2,3]

array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

let certs = [“aaa”,’bbb’,”ccc”];
let certValid = [222, 111, …certs, 333];

console.log(certValid);

A

[222, 111, “aaa”, “bbb”, “ccc”, 333]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

let certs = [“aaa”,’bbb’,”ccc”];
let certValid = [222, 111, certs, 333];

console.log(certValid);

A

[222, 111, [ “aaa”, “bbb”, “ccc”], 333]

adds the array into another array as an array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
function sum(x, y, z) {
  return x + y + z;
}

const numbers = [1, 2, 3];

console. log(sum(…numbers)); // spread operator
console. log(sum(_______)); // WRITE OLD WAY

A

console.log(sum(numbers1[0],numbers1[1],numbers1[2]));

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
const numbers = [1, 2, 3];
const numbers2 = // copy array with spread
A

const numbers2 = […numbers];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

let certs2 = […certs];
let certs = [“aaa”,’bbb’,”ccc”];

console.log(certs === certs2); // TRUE / FALSE

A

FALSE

OBJECTS are not the same in memory.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

let array1 = [1,2,3];
let array2 = [4,5,6];

let array3 = […array1, array2];
console.log(array3);

A

[1, 2, 3, [4,5,6]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

let array1 = [1,2,3];
let array2 = [4,5,6];

let array3 = […array1, …array2];
console.log(array3);

A

[1, 2, 3, 4, 5, 6];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

let array1 = [1,2,3];
let array2 = [4,5,6];

// concat with method
// concat with spread operator
A

array1.concat(array2);

let array3 = […array1, …array2];

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

the …spread operator does 4 things.

A
  1. //adds elements of an existing array into an new array.
  2. // pass elements of an array as arguments to a function
  3. // copy array
  4. // concat arrays
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

the _______ condenses an array

A

…rest

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

the ______ spreads out an array

A

…spread

17
Q

the rest operator ______ into an array

A

condense multiple elements

18
Q
var x = function  (...n){
}

in this block of code N will become ?

A

an array

19
Q
var x = function (){
    console.log(arguments);
    };
x(1,2,3) // returns?
A

an array like object but NOT an array

20
Q

When you pass an argument as a spread operator it’s called a _____

A

rest parameter