JS Code Flashcards
How do we do string interpolation in ES6?
We use the back ticks and the a dollar sign with Curly braces around the vriaableThis is a ${string}
How do we write a switch statement
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 do we use the ternary operator?
The termey operatoe is anothr way to write an if else statement
shootingFoul == true ? freeThrows(2) : continue;
How do we write arrow functions?
var shoot = () => { return jumper(); }
How do we use the for each iterator?
For Each goes through and performs an operation on each item in an array
fruits.forEach(=>
//some code
);
How do we use the map iterator?
let smallNumbers = bigNumbers.map(bN => bN / 100)
How do we use the filter iterator?
let small numbers = numbers.filter(sN =>
sN < 250);