Now we’re getting to It Flashcards

1
Q

JS: (expression) === VAR ? true: false;

A

Ternary operator evaluating for a Boolean response

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

JS: (expression) === VAR ? true :
(expression) ? true : false;

A

Nested ternary: basically if, else if, else
If the first returns false it moves into second line

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

JS: for (const VAR of ARRAY/STR) {
do something;
}

A

Basic for … of loop. Ideal to iterate thru arrays and strings

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

JS: const { key } = object;
console.log(key);
// prints ‘value’

A

A destructured assignment
Instead of
const key = object.key;

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

JS: const {key} = object;

key.nestedProperty;
or
key.nestedMethod();

A

More destructured assignment to access a nested property

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

.forEach() array iterates over array to return on each element but does not return a new array

A

JS: array.forEach(item => do something);

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

.map()
return a new array with the results of calling a provided function on every element of original array

A

const newArray = array.map(item =>
do_something);

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

.findIndex() to find the index of an element that matches given criteria

A

array.findIndex(i => i === 5);

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

JS: array.some()

A

Interator method that will check if there are ‘some’ given is criteria and return Boolean

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

.filter() to return a new array only with elements that pass a test

A

arr.filter(i => i != 5);
Returns array where i does not equal 5

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

.reduce() an array to a single value

A

array.reduce((accumulator, current) => {
return accumulator + current;
})

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

Short circuit evaluation (of an single if/else)
Eg.
if ‘thisVar’ exists use it,
else default to ‘that string

A

let variable = thisVar || ‘that string’;
Do something;

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

While Loop: continues while condition is true.

A

let i = 0;
while (i < 5) {
do_something;
i++
}

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

For loop. Runs a specified number of times.

A

for (let i = 0; i < 5; i ++) {
do _something;
}

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

For loop to iterate array

A

for (let i = 0; i < array.length; i ++) {
do_something _to _array;
}

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

Do While loop (guarantees at least one iteration over a While loop)

A

let i = 0

do {
do_something;
i++;
} while ( i < 5)