JS Code Flashcards

1
Q

How do we do string interpolation in ES6?

A

We use the back ticks and the a dollar sign with Curly braces around the vriaable
This is a ${string}

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

How do we write a switch statement

A

We use the switch keyword, parentheses and then within curly braces we list our various cases. After a case we use the break keyword to exit the switch statement.

switch (soda) {
 case 'cola':
  drink(soda);
break;
case 'saspirlla':
drink(soda);
break;
default:
drink(water);
break;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do we use the ternary operator?

A

The termey operatoe is anothr way to write an if else statement

shootingFoul == true ? freeThrows(2) : continue;

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

How do we write arrow functions?

A
var shoot = () => {
 return jumper();
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do we use the for each iterator?

A

For Each goes through and performs an operation on each item in an array

fruits.forEach(=>
//some code
);

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

How do we use the map iterator?

A
let smallNumbers = bigNumbers.map(bN =>
bN / 100)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do we use the filter iterator?

A

let small numbers = numbers.filter(sN =>

sN < 250);

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