This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In the for loop we directly destructure the array returned by heroes.entries(); | |
for (const[i, hero] of heroes.entries()) { | |
console.log(`${hero} is hero #${i + 1}`); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const heroes = ['The Hulk', 'Black Widow', 'Vision', 'Thor']; | |
for (const hero of heroes) { | |
if(hero === 'Black Widow') { | |
break; | |
} | |
console.log(hero); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function convertCurrency(amount) { | |
const converted = { | |
USD: amount * 0.76, | |
GBP: amount * 0.53, | |
AUD: amount * 1.01, | |
MEX: amount * 13.30 | |
}; | |
return converted; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reduce takes in two arguments, a function and an optional starting point. | |
// example 1 | |
[1, 2, 3].reduce((prev, curr, index) => { | |
console.log(prev, curr, index); | |
return prev + curr; | |
}); | |
// An example of a function that takes in any list of numbers as arguments | |
// and returns the total sum through a reduce function | |
function addNumbers() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let inRing = 'Hulk Hogan'; | |
let onSide = 'The Rock'; | |
console.log(inRing, onSide); | |
/* This might look a bit funky but what's happening is pretty simple: On the right | |
hand side we've got an array with the original values. As we give an array, we can | |
destructure it, which we do on the lefthand side. We destructure the array renaming | |
the `onSide` value to `inRing`and the `inRing` value to `onSide`*/ | |
[inRing, onSide] = [onSide, inRing]; | |
console.log(inRing, onSide); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const details = ['Arden', 123, 'arden.nl']; | |
// get a bunch of values out of the details array and name them as variable | |
const [name, id, website] = details; | |
console.log(name, id, website); | |
const data = 'Basketball,Sports,90210,23,super,man,cool'; | |
// We use data.split(',') which takes in the data string and returns it as an | |
// array which we immediately destructure with es6 array destructuring. | |
// When we have values that we do not call while destructuring, nothing will |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const person = { | |
first: 'Wes', | |
last: 'Bos', | |
country: 'Canada', | |
city: 'Hamilton', | |
twitter: '@wesbos', | |
}; | |
// Destructure an object as values with the keyname | |
const { first, last, twitter } = person; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const course = 'RFB2'; | |
const flightNumber = '20-AC2018-jz'; | |
const accountNumber = '825242631RT0001'; | |
const make = 'BMW'; | |
const model = 'x5'; | |
const colour = 'Royal Blue'; | |
// .startsWith(searchString [, position]) | |
// https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Tagged Templates</title> | |
<style> | |
abbr { | |
border-bottom:1px dotted grey; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dict = { | |
HTML: 'Hyper Text Markup Language', | |
CSS: 'Cascading Style Sheets', | |
JS: 'JavaScript' | |
}; | |
/* Create the function we tag onto the template string. Tagging it to a template | |
string automatically returns the strings seperated by values as an array (strings) | |
and gives the values as the rest of the argument. */ | |
function addAbrriviations(strings, ...values) { |