Brief introduction to Promises and ES6 syntax
Lili - @lilianakastilio
Some commonly used ES6 features
ES6 is the 6th Edition language specification for JavaScript from June 2015, you can find more info here:
www.ecma-international.org
Back in ES5 we used to use var, now in ES6 we have let and const.
Tip: Always use const and only use let when you need to be able to re-assign.
In ES5 creating a function looked like this:
In ES6 creating a function now looks like this:
String literals allow us to embed variables or expressions into a string
Looping through each item in the array
Return a new array by calling a function on each item in the original array
Promise is an assurance that something will happen in the future.
In JavaScript promises are often used to make sure we can do some async action and then process the data/result.
Start boiling the kettle | |
---|---|
Kettle is boiling | Grab sugar |
Kettle is boiling | Grab tea bag |
Kettle is boiling | Grab milk |
Kettle is boiling | Grab a mug |
Kettle is boiling | Put tea bag into the mug |
Kettle is boiling | |
Kettle finished boiling ⇒ | Pour hot water into mug |
Add milk | |
Add sugar | |
Stir |
https://codepen.io/lili2311/pen/NaMNaR (fork it and get started!)