SlideShare uma empresa Scribd logo
1 de 200
Modern JS with ES6
Kevin Langley Jr.
A Brief History
● May 1995 - Originally developed under the name Mocha.
A Brief History
● May 1995 - Originally developed under the name Mocha.
● September 1995 - Released originally as LiveScript.
A Brief History
● May 1995 - Originally developed under the name Mocha.
● September 1995 - Released originally as LiveScript.
● December 1995 - Renamed JavaScript with the release of Netscape Navigator 2.0.
A Brief History
● May 1995 - Originally developed under the name Mocha.
● September 1995 - Released originally as LiveScript.
● December 1995 - Renamed JavaScript with the release of Netscape Navigator 2.0.
● November 1996 - Netscape submitted JavaScript to Ecma International for
standardization.
A Brief History
● May 1995 - Originally developed under the name Mocha.
● September 1995 - Released originally as LiveScript.
● December 1995 - Renamed JavaScript with the release of Netscape Navigator 2.0.
● November 1996 - Netscape submitted JavaScript to Ecma International for
standardization.
● June 1997 - This resulted in a new language standard, known as ECMAScript.
A Brief History
● May 1995 - Originally developed under the name Mocha.
● September 1995 - Released originally as LiveScript.
● December 1995 - Renamed JavaScript with the release of Netscape Navigator 2.0.
● November 1996 - Netscape submitted JavaScript to Ecma International for
standardization.
● June 1997 - This resulted in a new language standard, known as ECMAScript.
● ECMAScript is the standard and JavaScript is the most popular implementation of
that standard and also builds on top of it.
A Brief History
ES is short for ECMAScript. Every time you see ES followed by a number, it is
referencing an edition of ECMAScript.
ES_???
● ES1: June 1997
ES is short for ECMAScript. Every time you see ES followed by a number, it is
referencing an edition of ECMAScript.
ES_???
● ES1: June 1997
● ES2: June 1998
ES is short for ECMAScript. Every time you see ES followed by a number, it is
referencing an edition of ECMAScript.
ES_???
● ES1: June 1997
● ES2: June 1998
● ES3: December 1999
ES is short for ECMAScript. Every time you see ES followed by a number, it is
referencing an edition of ECMAScript.
ES_???
ES is short for ECMAScript. Every time you see ES followed by a number, it is
referencing an edition of ECMAScript.
ES_???
● ES1: June 1997
● ES2: June 1998
● ES3: December 1999
● ES4: Abandoned
ES is short for ECMAScript. Every time you see ES followed by a number, it is
referencing an edition of ECMAScript.
ES_???
● ES1: June 1997
● ES2: June 1998
● ES3: December 1999
● ES4: Abandoned
● ES5: December 2009
● ES6/ES2015: June 2015
ES is short for ECMAScript. Every time you see ES followed by a number, it is
referencing an edition of ECMAScript.
ES_???
● ES1: June 1997
● ES2: June 1998
● ES3: December 1999
● ES4: Abandoned
● ES5: December 2009
● ES6/ES2015: June 2015
● ES7/ES2016: June 2016
ES is short for ECMAScript. Every time you see ES followed by a number, it is
referencing an edition of ECMAScript.
ES_???
● ES1: June 1997
● ES2: June 1998
● ES3: December 1999
● ES4: Abandoned
● ES5: December 2009
● ES6/ES2015: June 2015
● ES7/ES2016: June 2016
● ES8/ES2017: June 2017
ES is short for ECMAScript. Every time you see ES followed by a number, it is
referencing an edition of ECMAScript.
ES_???
● ES1: June 1997
● ES2: June 1998
● ES3: December 1999
● ES4: Abandoned
● ES5: December 2009
● ES6/ES2015: June 2015
● ES7/ES2016: June 2016
● ES8/ES2017: June 2017
● ES.Next: This term is dynamic and
references the next version of
ECMAScript coming out.
ES is short for ECMAScript. Every time you see ES followed by a number, it is
referencing an edition of ECMAScript.
ES_???
● ES1: June 1997
● ES2: June 1998
● ES3: December 1999
● ES4: Abandoned
● ES5: December 2009
The ECMA TC39 committee is responsible for evolving the ECMAScript programming
language and authoring the specification.
TC39
The ECMA TC39 committee is responsible for evolving the ECMAScript programming
language and authoring the specification.
● Stage 0 - Strawman
TC39
The ECMA TC39 committee is responsible for evolving the ECMAScript programming
language and authoring the specification.
● Stage 0 - Strawman
● Stage 1 - Proposal
TC39
The ECMA TC39 committee is responsible for evolving the ECMAScript programming
language and authoring the specification.
● Stage 0 - Strawman
● Stage 1 - Proposal
● Stage 2 - Draft
TC39
The ECMA TC39 committee is responsible for evolving the ECMAScript programming
language and authoring the specification.
● Stage 0 - Strawman
● Stage 1 - Proposal
● Stage 2 - Draft
● Stage 3 - Candidate
TC39
Modules allow you to load code asynchronously and provides a layer of
abstraction to your code.
ES6 Modules
Modules allow you to load code asynchronously and provides a layer of
abstraction to your code.
Two ways to export from a module.
ES6 Modules
Modules allow you to load code asynchronously and provides a layer of
abstraction to your code.
Two ways to export from a module.
● Multiple named exports
ES6 Modules
Modules allow you to load code asynchronously and provides a layer of
abstraction to your code.
Two ways to export from a module.
● Multiple named exports
● Single default export
ES6 Modules
mathlib.js
ES6 Modules - Multiple Named Exports
function square(x) {
return x * x;
}
mathlib.js
ES6 Modules - Multiple Named Exports
mathlib.js
ES6 Modules - Multiple Named Exports
function square(x) {
return x * x;
}
function add(x, y) {
return x + y;
}
mathlib.js
ES6 Modules - Multiple Named Exports
export function square(x) {
return x * x;
}
export function add(x, y) {
return x + y;
}
mathlib.js
ES6 Modules - Multiple Named Exports
export function square(x) {
return x * x;
}
export function add(x, y) {
return x + y;
}
main.js
mathlib.js
ES6 Modules - Multiple Named Exports
export function square(x) {
return x * x;
}
export function add(x, y) {
return x + y;
}
main.js
console.log(square(9)); // 81
console.log(add(4, 3)); // 7
mathlib.js
ES6 Modules - Multiple Named Exports
export function square(x) {
return x * x;
}
export function add(x, y) {
return x + y;
}
main.js
import { square, add } from 'mathlib';
console.log(square(9)); // 81
console.log(add(4, 3)); // 7
foo.js
ES6 Modules - Single Default Exports
foo.js
ES6 Modules - Single Default Exports
export default function() {
console.log('Foo!');
}
foo.js
ES6 Modules - Single Default Exports
export default function() {
console.log('Foo!');
}
main.js
import foo from 'foo';
foo(); // Foo!
ES6 Tools
ES6 Tools
Variable Scoping
var is function scoped.
var vs let vs const
if ( true ) {
var foo = 'bar';
}
console.log( foo );
// bar
let and const are block scoped.
if ( true ) {
let foo = 'bar';
const bar = 'foo';
}
console.log( foo );
console.log( bar );
// ReferenceError.
// ReferenceError.
let and const
let first = 'First string';
{
let second = 'Second string';
{
let third = 'Third string';
}
// Accessing third here would throw a ReferenceError.
}
// Accessing second here would throw a ReferenceError.
// Accessing third here would throw a ReferenceError.
let and const
const first = 'First string';
{
const second = 'Second string';
{
const third = 'Third string';
}
// Accessing third here would throw a ReferenceError.
}
// Accessing second here would throw a ReferenceError.
// Accessing third here would throw a ReferenceError.
Object.freeze() prevents changing
the properties.
const
const foo = { bar: 1 };
foo = 'bar';
// “foo” is read only.
foo.bar = 2;
console.log(foo);
// { bar: 2 }
But, you can change the properties!
const variables can only be assigned
once. It is NOT immutable.
const foo2 = Object.freeze(foo);
foo2.bar = 3;
console.log(foo2.bar); // 2
Object.seal(foo);
foo.baz = false; // TypeError
Object.seal() prevents changing the
object structure.
Variable Hoisting
Hoisting is a JavaScript mechanism where variables and function
declarations are moved to the top of their scope before code execution.
Variable Hoisting
Hoisting is a JavaScript mechanism where variables and function
declarations are moved to the top of their scope before code execution.
Which means you can do this with functions and vars:
sayHello();
function sayHello() {
console.log('Hello!');
}
console.log( foobar );
var foobar = 'Woot!'
Variable Hoisting
Hoisting is a JavaScript mechanism where variables and function
declarations are moved to the top of their scope before code execution.
Which means you can do this with functions and vars:
sayHello(); // Hello!
function sayHello() {
console.log('Hello!');
}
console.log( foobar );
// undefined
var foobar = 'Woot!'
new Thing();
class Thing{};
console.log(foo);
let foo = true;
console.log(bar);
const bar = true;
Variable Hoisting
In ES6, classes, let, and const variables are hoisted but they are not
initialized yet unlike vars and functions.
new Thing();
class Thing{};
console.log(foo);
let foo = true;
console.log(bar);
const bar = true;
Variable Hoisting
In ES6, classes, let, and const variables are hoisted but they are not
initialized yet unlike vars and functions.
// TypeError
// 'foo' was used before it was
defined
// 'bar' was used before it was
defined
Temporal Dead Zone
The variable is in a temporal dead zone
from the start of the block until the
initialization is processed.
if ( true ) { // TDZ starts!
}
Temporal Dead Zone
The variable is in a temporal dead zone
from the start of the block until the
initialization is processed.
if ( true ) { // TDZ starts!
const doSomething = function () {
console.log( thing ); // OK!
};
}
Temporal Dead Zone
The variable is in a temporal dead zone
from the start of the block until the
initialization is processed.
if ( true ) { // TDZ starts!
const doSomething = function () {
console.log( thing ); // OK!
};
doSomething(); // ReferenceError
}
Temporal Dead Zone
The variable is in a temporal dead zone
from the start of the block until the
initialization is processed.
if ( true ) { // TDZ starts!
const doSomething = function () {
console.log( thing ); // OK!
};
doSomething(); // ReferenceError
let thing = 'test'; // TDZ ends.
}
Temporal Dead Zone
The variable is in a temporal dead zone
from the start of the block until the
initialization is processed.
if ( true ) { // TDZ starts!
const doSomething = function () {
console.log( thing ); // OK!
};
doSomething(); // ReferenceError
let thing = 'test'; // TDZ ends.
doSomething();
// Called outside TDZ!
}
But, what should I use?!? var? let? const?
The only difference between const and let is that const makes the
contract that no rebinding will happen.
But, what should I use?!? var? let? const?
Mathias Bynens - V8 Engineer @ Google
● Use const by default.
● Only use let if rebinding is needed.
● var shouldn’t be used in ES2015.
The only difference between const and let is that const makes the
contract that no rebinding will happen.
But, what should I use?!? var? let? const?
Mathias Bynens - V8 Engineer @ Google
● Use const by default.
● Only use let if rebinding is needed.
● var shouldn’t be used in ES2015.
Kyle Simpson - Founder @ Getify
Solutions
● Use var for top level variables
● Use let for localized variables in
smaller scopes.
● Refactor let to const only after some
code has been written and you’re
reasonably sure there shouldn’t be
variable reassignment.
The only difference between const and let is that const makes the
contract that no rebinding will happen.
Iterables & Looping
When using var, you leak a global variable to the parent scope and the
variable gets overwritten with every iteration.
Iterables & Looping
When using var, you leak a global variable to the parent scope and the
variable gets overwritten with every iteration.
for ( var i = 0; i < 10; i++ ) {
setTimeout( function() {
console.log( 'Number: ' + i );
}, 1000 );
}
// Number: 10
// Number: 10
// Number: 10
// Number: 10
// Number: 10
Iterables & Looping
When using var, you leak a global variable to the parent scope and the
variable gets overwritten with every iteration.
for ( var i = 0; i < 10; i++ ) {
setTimeout( function() {
console.log( 'Number: ' + i );
}, 1000 );
}
// Number: 10
// Number: 10
// Number: 10
// Number: 10
// Number: 10
Iterables & Looping
Using let in a for loop allows us to have the variable scoped to its block
only.
Iterables & Looping
Using let in a for loop allows us to have the variable scoped to its block
only.
for ( let i = 0; i < 10; i++ ) {
setTimeout( function() {
console.log( 'Number: ' + i );
}, 1000 );
}
// Number: 0
// Number: 1
// Number: 2
// Number: 3
// Number: 4
Iterables & Looping
Using let in a for loop allows us to have the variable scoped to its block
only.
for ( let i = 0; i < 10; i++ ) {
setTimeout( function() {
console.log( 'Number: ' + i );
}, 1000 );
}
// Number: 5
// Number: 6
// Number: 7
// Number: 8
// Number: 9
const iterable = [10, 20, 30];
for (const value of iterable) {
console.log(value);
}
// 10
// 20
// 30
Iterables & Looping
ES6 also gives us a new way to loop over iterables!
const articleParagraphs = document.querySelectorAll('article > p');
for (const paragraph of articleParagraphs) {
paragraph.classList.add('read');
}
Iterables & Looping
ES6 also gives us a new way to loop over iterables!
const foo = 'bar';
for (const letter of foo) {
console.log(letter);
}
// b
// a
// r
Iterables & Looping
ES6 also gives us a new way to loop over iterables!
Arrow Functions
// Traditional function expression.
const addNumbers = function (num1, num2) {
return num1 + num2;
}
More concise than traditional function expressions:
Arrow Functions
More concise than traditional function expressions:
Arrow Functions
// Traditional function expression.
const addNumbers = function (num1, num2) {
return num1 + num2;
}
// Arrow function expression.
const addNumbers = (num1, num2) => {
return num1 + num2;
}
Arrow functions have implicit returns:
Arrow Functions
// Traditional function expression.
const addNumbers = function (num1, num2) {
return num1 + num2;
}
// Arrow function expression with implicit return.
const addNumbers = (num1, num2) => num1 + num2;
// Arrow function without any arguments.
const sayHello = () => console.log( 'Hello!' );
A few more examples:
Arrow Functions
// Arrow function without any arguments.
const sayHello = () => console.log( 'Hello!' );
// Arrow function with a single argument.
const sayHello = name => console.log( `Hello ${name}!` );
A few more examples:
Arrow Functions
A few more examples:
Arrow Functions
// Arrow function without any arguments.
const sayHello = () => console.log( 'Hello!' );
// Arrow function with a single argument.
const sayHello = name => console.log( `Hello ${name}!` );
// Arrow function with multiple arguments.
const sayHello = (fName, lName) => console.log( `Hello ${fName} ${lName}!` );
function Person(){
this.age = 0;
setInterval(function() {
this.age++; // `this`refers to the Window.
}, 1000);
}
The value of this is picked up from its surroundings (lexical).
Therefore, you don’t need bind(), that, or self anymore!
Arrow Functions
function Person(){
var that = this;
this.age = 0;
setInterval(function() {
that.age++; // Without arrow functions. Works, but is not ideal.
}, 1000);
}
The value of this is picked up from its surroundings (lexical).
Therefore, you don’t need bind(), that, or self anymore!
Arrow Functions
function Person(){
this.age = 0;
setInterval(() => {
this.age++; // `this` properly refers to the person object.
}, 1000);
}
The value of this is picked up from its surroundings (lexical).
Therefore, you don’t need bind(), that, or self anymore!
Arrow Functions
const button = document.querySelector('#my-button');
button.addEventListener('click', () => {
this.classList.toggle('on');
})
When should I not use arrow functions?
Arrow Functions
const button = document.querySelector('#my-button');
button.addEventListener('click', () => {
this.classList.toggle('on'); // `this`refers to the Window.
})
When should I not use arrow functions?
Arrow Functions
Default Arguments
function calculateTotal( subtotal, tax, shipping ) {
return subtotal + shipping + (subtotal * tax);
}
const total = calculateTotal(100, 0.07, 10);
Here’s a basic function.
Default Arguments
function calculateTotal( subtotal, tax, shipping ) {
return subtotal + shipping + (subtotal * tax);
}
const total = calculateTotal(100, 0.07, 10);
Let’s add some defaults to the arguments in our function expression!
Default Arguments
function calculateTotal( subtotal, tax, shipping ) {
if ( tax === undefined ) {
tax = 0.07;
}
if ( shipping === undefined ) {
shipping = 10;
}
return subtotal + shipping + (subtotal * tax);
}
const total = calculateTotal(100);
The Old Way
Default Arguments
function calculateTotal( subtotal, tax, shipping ) {
tax = tax || 0.07;
shipping = shipping || 10;
return subtotal + shipping + (subtotal * tax);
}
const total = calculateTotal(100);
A little better?
Default Arguments
function calculateTotal( subtotal, tax = 0.07, shipping = 10 ) {
return subtotal + shipping + (subtotal * tax);
}
const total = calculateTotal(100);
Now with ES6!
Default Arguments
function calculateTotal( subtotal, tax = 0.07, shipping = 10 ) {
return subtotal + shipping + (subtotal * tax);
}
const total = calculateTotal(100, , 20); // Can I do this?
What if I wanted to only pass in the first and third argument?
Default Arguments
function calculateTotal( subtotal, tax = 0.07, shipping = 10 ) {
return subtotal + shipping + (subtotal * tax);
}
const total = calculateTotal(100, , 20); // SyntaxError
What if I wanted to only pass in the first and third argument?
Default Arguments
function calculateTotal( subtotal, tax = 0.07, shipping = 10 ) {
return subtotal + shipping + (subtotal * tax);
}
const total = calculateTotal(100, undefined, 20); //
What if I wanted to only pass in the first and third argument?
Default Arguments
Destructuring
const person = {
first: 'Kevin',
last: 'Langley',
location: {
city: 'Beverly Hills',
state: 'Florida'
}
};
Destructuring Objects
const person = {
first: 'Kevin',
last: 'Langley',
location: {
city: 'Beverly Hills',
state: 'Florida'
}
};
const first = person.first;
const last = person.last;
Destructuring Objects
Let’s create some variables from the object properties.
const person = {
first: 'Kevin',
last: 'Langley',
location: {
city: 'Beverly Hills',
state: 'Florida'
}
};
const { first, last } = person;
Destructuring Objects
Let’s do that using destructuring.
const person = {
first: 'Kevin',
last: 'Langley',
location: {
city: 'Beverly Hills',
state: 'Florida'
}
};
const { first, last } = person;
const { city, state } = person.location;
Destructuring Objects
It even works with nested properties.
const person = {
first: 'Kevin',
last: 'Langley',
location: {
city: 'Beverly Hills',
state: 'Florida'
}
};
const { first: fName, last: lName } = person;
const { city: locationCity, state: locationState } = person.location;
Destructuring Objects
You can also rename the variables from the destructured object!
const settings = { color: 'white', height: 500 };
const { width, height, color } = settings;
Destructuring Objects
What if I tried to destruct a property that doesn’t exist?
const settings = { color: 'white', height: 500 };
const { width, height, color } = settings;
console.log(width); // undefined
console.log(height); // 500
console.log(color); // white
Destructuring Objects
What if I tried to destruct a property that doesn’t exist?
const settings = { color: 'white', height: 500 };
const { width = 200, height = 200, color = 'black' } = settings;
Destructuring Objects
But, you can set defaults in your destructuring!
const settings = { color: 'white', height: 500 };
const { width = 200, height = 200, color = 'black' } = settings;
console.log(width); // 200
console.log(height); // 500
console.log(color); // white
Destructuring Objects
But, you can set defaults in your destructuring!
const details = [ 'Kevin', 'Langley', 'kevinlangleyjr.com' ];
Destructuring Arrays
You can destructure arrays as well!
const details = [ 'Kevin', 'Langley', 'kevinlangleyjr.com' ];
const [ first, last, website ] = details;
Destructuring Arrays
You can destructure arrays as well!
const details = [ 'Kevin', 'Langley', 'kevinlangleyjr.com' ];
const [ first, last, website ] = details;
console.log(first); // Kevin
console.log(last); // Langley
console.log(website); // kevinlangleyjr.com
Destructuring Arrays
You can destructure arrays as well!
Spread… and ...Rest
function doSomething (x, y, z) {
console.log(x, y, z);
}
let args = [0, 1, 2];
// Call the function, passing args.
doSomething.apply(null, args);
...Spread Operator
Before ES6, we would run .apply() to pass in an array of arguments.
function doSomething (x, y, z) {
console.log(x, y, z);
}
let args = [0, 1, 2];
// Call the function, without `apply`, passing args with the spread operator!
doSomething(...args);
...Spread Operator
But with ES6, we can use the spread operator ... to pass in the arguments.
let array1 = ['one', 'two', 'three'];
let array2 = ['four', 'five'];
array1.push(...array2) // Adds array2 items to end of array
array1.unshift(...array2) //Adds array2 items to beginning of array
...Spread Operator
We can also use the spread operator to combine arrays.
let array1 = ['two', 'three'];
let array2 = ['one', ...array1, 'four', 'five'];
console.log(array2); // ["one", "two", "three", "four", "five"]
...Spread Operator
We can also use the spread operator to combine arrays at any point.
let array1 = [1,2,3];
let array2 = [...array1]; // like array1.slice()
array2.push(4)
console.log(array1); // [1,2,3]
console.log(array2); // [1,2,3,4]
...Spread Operator
We can also use the spread operator to create a copy of an array.
const players = [ 'Kevin', 'Bobby', 'Nicole', 'Naomi', 'Jim', 'Sherry' ];
const [ first, second, third, ...unplaced ] = players;
console.log(first); // Kevin
console.log(second); // Bobby
console.log(third); // Nicole
console.log(unplaced); // ["Naomi", "Jim", "Sherry"]
...Spread Operator
We can also use the spread operator with destructuring.
const { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 };
console.log(x); // 1
console.log(y); // 2
console.log(z); // { a: 3, b: 4 }
...Spread Operator
We can also use the spread operator with destructuring.
const elements = [...document.querySelectorAll('div')];
console.log(elements); // Lists all the div's on the page.
...Spread Operator
We can also use the spread operator to expand a NodeList.
function doMath(operator, ...numbers) {
console.log(operator); // 'add'
console.log(numbers); // [1, 2, 3]
}
doMath('add', 1, 2, 3);
...Rest Operator
The rest operator allows us to more easily handle a variable number of function
parameters.
Strings
const name = 'Kevin';
// The old way...
console.log('Hello, ' + name + '!'); // Hello, Kevin!
Template Literals
The Template Literal, introduced in ES6, is a new way to create a string.
Template Literals
The Template Literal, introduced in ES6, is a new way to create a string.
const name = 'Kevin';
// The old way...
console.log('Hello, ' + name + '!'); // Hello, Kevin!
// With ES6 template literals.
console.log(`Hello, ${name}!`); // Hello, Kevin!
Template Literals
Within template literals you can evaluate expressions.
const price = 19.99;
const tax = 0.07;
const total = `The total price is ${price + (price * tax)}`;
console.log(total);
// The total price is 21.3893
Template Literals
With template literals you can more easily create multi-line strings.
console.log('This is some text that flows acrossntwo lines!');
// "This is some text that flows across
// two lines!"
console.log(`But so does
this text!`);
// "But so does
// this text!"
New String Methods - .startsWith()
const str = 'Learn JavaScript Deeply';
console.log(str.startsWith('Learn')); // true
console.log(str.startsWith('JavaScript')); // false
console.log(str.startsWith('Deeply', 17)); // true
New String Methods - .endsWith()
const str = 'Learn JavaScript Deeply';
console.log(str.endsWith('Deeply')); // true
console.log(str.endsWith('Learn')); // false
console.log(str.endsWith('JavaScript', 16)); // true
New String Methods - .includes()
const str = 'Learn JavaScript Deeply';
console.log(str.includes('JavaScript')); // true
console.log(str.includes('Javascript')); // false
console.log(str.includes('PHP')); // false
New String Methods - .repeat()
const str = 'Deeply';
console.log(str.repeat(3)); // DeeplyDeeplyDeeply
console.log(str.repeat(2.5)); // DeeplyDeeply (converts to int)
console.log(str.repeat(-1)); // RangeError
Enhanced Object Literals
Enhanced Object Literals
const first = 'Kevin';
const last = 'Langley';
const age = 29;
Enhanced Object Literals
const first = 'Kevin';
const last = 'Langley';
const age = 29;
const person = {
first: first,
last: last,
age: age
};
Let’s assign our variables to properties of an object!
Enhanced Object Literals
const first = 'Kevin';
const last = 'Langley';
const age = 29;
const person = {
first,
last,
age
};
Let’s assign our variables to properties of an object!
Enhanced Object Literals
const first = 'Kevin';
const last = 'Langley';
const age = 29;
const person = {
firstName: first,
lastName: last,
age: age
};
Let’s assign our variables to properties of an object!
Enhanced Object Literals
var obj = {
foo: function() {
console.log('foo');
},
bar: function() {
console.log('bar');
}
};
We can also use a shorter syntax for method definitions on objects initializers.
Enhanced Object Literals
We can also use a shorter syntax for method definitions on objects initializers.
const obj = {
foo() {
console.log('foo');
},
bar() {
console.log('bar');
}
};
Enhanced Object Literals
Or even define keys that evaluate on run time inside object literals.
let i = 0;
const a = {
['foo' + ++i]: i,
['foo' + ++i]: i,
['foo' + ++i]: i
};
console.log(a.foo1); // 1
console.log(a.foo2); // 2
console.log(a.foo3); // 3
let i = 0;
const a = {
[`foo${++i}`]: i,
[`foo${++i}`]: i,
[`foo${++i}`]: i
};
console.log(a.foo1); // 1
console.log(a.foo2); // 2
console.log(a.foo3); // 3
Enhanced Object Literals
Let’s use template literals for those keys instead!
New Array Features!
Array.from()
const headers = document.querySelectorAll('h1');
Array.from()
const headers = document.querySelectorAll('h1');
const titles = headers.map(h1 => h1.textContent);
Array.from()
const headers = document.querySelectorAll('h1');
const titles = headers.map(h1 => h1.textContent);
// TypeError: headers.map is not a function
Array.from()
const headers = document.querySelectorAll('h1');
const headersArray = [...headers];
const titles = headersArray.map(h1 => h1.textContent);
Array.from()
const headers = document.querySelectorAll('h1');
const headersArray = Array.from(headers);
const titles = headersArray.map(h1 => h1.textContent);
Array.from()
const headers = document.querySelectorAll('h1');
const titles = Array.from(headers, h1 => {
return h1.textContent;
});
Array.from()
const titles = Array.from(document.querySelectorAll('h1'), h1 => {
return h1.textContent;
});
Array.from()
const headers = Array.from(document.querySelectorAll('h1'));
const titles = headers.map(header => header.textContent);
Array.from()
const headers = document.querySelectorAll('h1');
const titles = Array.from(headers, header => header.textContent);
Array.of()
const values = Array.of(123, 456, 789);
Array.of()
const values = Array.of(123, 456, 789);
console.log(values);
Array.of()
const values = Array.of(123, 456, 789);
console.log(values); // [123,456,789]
Array.find()
const posts = [
{
id: 1,
title: 'Hello World!'
},
{
id: 2,
title: 'Learn JS Deeply!'
}
];
Array.find()
const posts = [
{
id: 1,
title: 'Hello World!'
},
{
id: 2,
title: 'Learn JS Deeply!'
}
];
Array.find()
const posts = [
{
id: 1,
title: 'Hello World!'
},
{
id: 2,
title: 'Learn JS Deeply!'
}
];
posts.2
Array.find()
const posts = [
{
id: 1,
title: 'Hello World!'
},
{
id: 2,
title: 'Learn JS Deeply!'
}
];
posts[2]
Array.find()
const posts = [
{
id: 1,
title: 'Hello World!'
},
{
id: 2,
title: 'Learn JS Deeply!'
}
];
const post = posts.find(post => post.id === 2);
Array.find()
const posts = [
{
id: 1,
title: 'Hello World!'
},
{
id: 2,
title: 'Learn JS Deeply!'
}
];
const post = posts.find(post => post.id === 2);
console.log(post);
Array.find()
const posts = [
{
id: 1,
title: 'Hello World!'
},
{
id: 2,
title: 'Learn JS Deeply!'
}
];
const post = posts.find(post => post.id === 2);
console.log(post); // {id: 2, title: "Learn JS Deeply!"}
Array.findIndex()
const posts = [
{
id: 1,
title: 'Hello World!'
},
{
id: 2,
title: 'Learn JS Deeply!'
}
];
const post = posts.findIndex(post => post.id === 2);
Array.findIndex()
const posts = [
{
id: 1,
title: 'Hello World!'
},
{
id: 2,
title: 'Learn JS Deeply!'
}
];
const post = posts.findIndex(post => post.id === 2);
console.log(post);
Array.findIndex()
const posts = [
{
id: 1,
title: 'Hello World!'
},
{
id: 2,
title: 'Learn JS Deeply!'
}
];
const post = posts.findIndex(post => post.id === 2);
console.log(post); // 1
Promises
const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts');
Promises
const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts');
console.log(postsPromise);
Promises
Promises
const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts');
console.log(postsPromise);
// Promise {<pending>}
// __proto__: Promise
// [[PromiseStatus]]: "pending"
// [[PromiseValue]]: undefined
const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts');
Promises
const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts');
postsPromise.then(data => console.log(data));
Promises
const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts');
postsPromise.then(data => console.log(data));
// Response {type: "cors", url: "https://2018.miami.wordcamp.org/wp-
json/wp/v2/posts", redirected: false, status: 200, ok: true, …}
Promises
const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts');
postsPromise.then(data => data.json())
Promises
const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts');
postsPromise.then(data => data.json()).then(data => console.log(data));
Promises
const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts');
postsPromise.then(data => data.json()).then(data => console.log(data));
// {id: 5060, date: "2018-03-15T17:41:09", ...}
// {id: 4954, date: "2018-03-14T00:21:10", ...}
// {id: 4943, date: "2018-03-13T19:16:11", ...}
// {id: 4702, date: "2018-03-10T11:04:36", ...}
// ...
Promises
const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts');
postsPromise
.then(data => data.json())
.then(data => console.log(data))
Promises
const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts');
postsPromise
.then(data => data.json())
.then(data => console.log(data))
.catch(err);
Promises
const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts');
postsPromise
.then(data => data.json())
.then(data => console.log(data))
.catch(err => console.error(err));
Promises
const postsPromise = fetch('https://2019.miami.wordcamp.org/wp-json/wp/v2/posts');
postsPromise
.then(data => data.json())
.then(data => console.log(data))
.catch(err => console.error(err));
Promises
const postsPromise = fetch('https://2019.miami.wordcamp.org/wp-json/wp/v2/posts');
postsPromise
.then(data => data.json())
.then(data => console.log(data))
.catch(err => console.error(err));
// TypeError: Failed to fetch
Promises
const p = new Promise((resolve, reject) => {
});
Promises
const p = new Promise((resolve, reject) => {
resolve();
});
Promises
const p = new Promise((resolve, reject) => {
reject();
});
Promises
const p = new Promise((resolve, reject) => {
resolve('Learn JavaScript Deeply!');
});
p.then(data => console.log(data));
Promises
const p = new Promise((resolve, reject) => {
resolve('Learn JavaScript Deeply!');
});
p.then(data => console.log(data)); // Learn JavaScript Deeply
Promises
const p = new Promise((resolve, reject) => {
reject(Error('Uh oh!'));
});
p.then(data => console.log(data));
Promises
const p = new Promise((resolve, reject) => {
reject(Error('Uh oh!'));
});
p.then(data => console.log(data));
// Uncaught (in promise) Error: Uh oh!
Promises
const p = new Promise((resolve, reject) => {
reject(Error('Uh oh!'));
});
p
.then(data => console.log(data));
.catch(err => console.error(err));
// Error: Uh oh!
Promises
Classes
Classes
// Class declaration
class Animal {
}
// Class expression
const Animal = class {
}
class Animal {
}
Classes
class Animal {
constructor(name) {
this.name = name;
}
}
Classes
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise.`);
}
}
Classes
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise.`);
}
}
class Dog extends Animal {
}
Classes
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise.`);
}
}
class Dog extends Animal {
speak() {
console.log(`${this.name} barks!`);
}
}
Classes
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise.`);
}
}
class Dog extends Animal {
speak() {
console.log(`${this.name} barks!`);
}
}
const puppy = new Dog('Spot');
puppy.speak(); // Spot barks!
Classes
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise.`);
}
}
class Dog extends Animal {
constructor(name, breed) {
this.breed = breed;
}
speak() {
console.log(`${this.name} barks!`);
}
}
Classes
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise.`);
}
}
class Dog extends Animal {
constructor(name, breed) {
super(name);
this.breed = breed;
}
speak() {
console.log(`${this.name} barks!`);
}
}
Classes
function resolveAfter(time) {
}
Async & Await
function resolveAfter(time) {
return new Promise(resolve => {
});
}
Async & Await
function resolveAfter(time) {
return new Promise(resolve => {
setTimeout(() => {
}, time);
});
}
Async & Await
function resolveAfter(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve('Resolved after ${time} milliseconds');
}, time);
});
}
Async & Await
function resolveAfter(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve('Resolved after ${time} milliseconds');
}, time);
});
}
console.log('Starting resolveAfter()');
const result = resolveAfter(500);
console.log(result);
console.log('Ending resolveAfter()');
// Starting resolveAfter()
// Promise {<pending>}
// __proto__: Promise
// [[PromiseStatus]]: "pending"
// [[PromiseValue]]: undefined
// Ending resolveAfter()
Async & Await
async function resolveAfter(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve('Resolved after ${time} milliseconds');
}, time);
});
}
console.log('Starting resolveAfter()');
const result = await resolveAfter(500);
console.log(result);
console.log('Ending resolveAfter()');
// SyntaxError: await is only valid in async
function
Async & Await
function resolveAfter(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve('Resolved after ${time} milliseconds');
}, time);
});
}
async function asyncCall() {
console.log('Starting asyncCall()');
const result = await resolveAfter(500);
console.log(result);
console.log('Ending asyncCall()');
}
asyncCall();
Async & Await
// 08:14:22.852 Starting asyncCall()
// 08:14:23.474 Resolved after 500 milliseconds
// 08:14:38.483 Ending asyncCall()
function resolveAfter(time) {
return new Promise(resolve => {
setTimeout(() => {
resolve('Resolved after ${time} milliseconds');
}, time);
});
}
async function asyncCall() {
console.log('Starting asyncCall()');
const result1 = await resolveAfter(500);
console.log(result1);
const result2 = await resolveAfter(5000);
console.log(result2);
console.log('Ending asyncCall()');
}
asyncCall();
// 08:14:22.852 Starting asyncCall()
// 08:14:23.474 Resolved after 500 milliseconds
// 08:14:28.478 Resolved after 5000 milliseconds
// 08:14:38.483 Ending asyncCall()
Async & Await
● Generators
Features! Features! Features!
● Generators
● Symbols
Features! Features! Features!
● Generators
● Symbols
● Proxies
Features! Features! Features!
● Generators
● Symbols
● Proxies
● Sets and WeakSets
Features! Features! Features!
Features! Features! Features!
● Generators
● Symbols
● Proxies
● Sets and WeakSets
● Maps and WeakMaps
Features! Features! Features!
● Generators
● Symbols
● Proxies
● Sets and WeakSets
● Maps and WeakMaps
● And even more that is still in review by TC39!
Still have questions?
Wes Bos - ES6 for Everyone - http://es6.io
Thank you!

Mais conteúdo relacionado

Mais procurados

React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXLRob Gietema
 
Angular Pipes Workshop
Angular Pipes WorkshopAngular Pipes Workshop
Angular Pipes WorkshopNir Kaufman
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?FITC
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js ExpressEyal Vardi
 
History of JavaScript
History of JavaScriptHistory of JavaScript
History of JavaScriptRajat Saxena
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScriptAndres Baravalle
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Edureka!
 
Working with Dynamic Content and Adding Templating engines, MVC
Working with Dynamic Content and Adding Templating engines, MVCWorking with Dynamic Content and Adding Templating engines, MVC
Working with Dynamic Content and Adding Templating engines, MVCKnoldus Inc.
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...Edureka!
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptLaurence Svekis ✔
 

Mais procurados (20)

React Router: React Meetup XXL
React Router: React Meetup XXLReact Router: React Meetup XXL
React Router: React Meetup XXL
 
Angular Pipes Workshop
Angular Pipes WorkshopAngular Pipes Workshop
Angular Pipes Workshop
 
Why TypeScript?
Why TypeScript?Why TypeScript?
Why TypeScript?
 
Express js
Express jsExpress js
Express js
 
Brief History of JavaScript
Brief History of JavaScriptBrief History of JavaScript
Brief History of JavaScript
 
Node.js Express
Node.js  ExpressNode.js  Express
Node.js Express
 
History of JavaScript
History of JavaScriptHistory of JavaScript
History of JavaScript
 
Introduction to JavaScript
Introduction to JavaScriptIntroduction to JavaScript
Introduction to JavaScript
 
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
Node.js Tutorial for Beginners | Node.js Web Application Tutorial | Node.js T...
 
Working with Dynamic Content and Adding Templating engines, MVC
Working with Dynamic Content and Adding Templating engines, MVCWorking with Dynamic Content and Adding Templating engines, MVC
Working with Dynamic Content and Adding Templating engines, MVC
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
 
React js
React jsReact js
React js
 
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js +  Expres...
Node.js Express Tutorial | Node.js Tutorial For Beginners | Node.js + Expres...
 
Angular
AngularAngular
Angular
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Javascript essentials
Javascript essentialsJavascript essentials
Javascript essentials
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
ReactJS presentation.pptx
ReactJS presentation.pptxReactJS presentation.pptx
ReactJS presentation.pptx
 
JavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScriptJavaScript guide 2020 Learn JavaScript
JavaScript guide 2020 Learn JavaScript
 

Semelhante a Modern JS with ES6

Fitc whats new in es6 for web devs
Fitc   whats new in es6 for web devsFitc   whats new in es6 for web devs
Fitc whats new in es6 for web devsFITC
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web DevsRami Sayar
 
Living in harmony - a brief into to ES6
Living in harmony - a brief into to ES6Living in harmony - a brief into to ES6
Living in harmony - a brief into to ES6Richard Leland
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is hereSebastiano Armeli
 
JavaScript: Core Part
JavaScript: Core PartJavaScript: Core Part
JavaScript: Core Part維佋 唐
 
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...Mario Heiderich
 
15646254 c-balaguruswamy-solved-programs
15646254 c-balaguruswamy-solved-programs15646254 c-balaguruswamy-solved-programs
15646254 c-balaguruswamy-solved-programspremrings
 
How Functions Work
How Functions WorkHow Functions Work
How Functions WorkSaumil Shah
 
Tamarin and ECMAScript 4
Tamarin and ECMAScript 4Tamarin and ECMAScript 4
Tamarin and ECMAScript 4jeresig
 
Intro to ES6 and why should you bother !
Intro to ES6 and why should you bother !Intro to ES6 and why should you bother !
Intro to ES6 and why should you bother !Gaurav Behere
 
Making ES6 available to all with ChakraCore and Typescript
Making ES6 available to all with ChakraCore and TypescriptMaking ES6 available to all with ChakraCore and Typescript
Making ES6 available to all with ChakraCore and TypescriptChristian Heilmann
 
Tamarin And Ecmascript 4
Tamarin And Ecmascript 4Tamarin And Ecmascript 4
Tamarin And Ecmascript 4elliando dias
 
Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -LynellBull52
 
Modern JavaScript features
Modern JavaScript featuresModern JavaScript features
Modern JavaScript featuresKunal Kursija
 

Semelhante a Modern JS with ES6 (20)

Modern JS with ES6
Modern JS with ES6Modern JS with ES6
Modern JS with ES6
 
Fitc whats new in es6 for web devs
Fitc   whats new in es6 for web devsFitc   whats new in es6 for web devs
Fitc whats new in es6 for web devs
 
What's New in ES6 for Web Devs
What's New in ES6 for Web DevsWhat's New in ES6 for Web Devs
What's New in ES6 for Web Devs
 
ECMAScript 6
ECMAScript 6ECMAScript 6
ECMAScript 6
 
JavaScript im Jahr 2016
JavaScript im Jahr 2016JavaScript im Jahr 2016
JavaScript im Jahr 2016
 
Living in harmony - a brief into to ES6
Living in harmony - a brief into to ES6Living in harmony - a brief into to ES6
Living in harmony - a brief into to ES6
 
ES6: The future is now
ES6: The future is nowES6: The future is now
ES6: The future is now
 
EcmaScript 6 - The future is here
EcmaScript 6 - The future is hereEcmaScript 6 - The future is here
EcmaScript 6 - The future is here
 
JavaScript: Core Part
JavaScript: Core PartJavaScript: Core Part
JavaScript: Core Part
 
Flex
FlexFlex
Flex
 
Es6 to es5
Es6 to es5Es6 to es5
Es6 to es5
 
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
 
15646254 c-balaguruswamy-solved-programs
15646254 c-balaguruswamy-solved-programs15646254 c-balaguruswamy-solved-programs
15646254 c-balaguruswamy-solved-programs
 
How Functions Work
How Functions WorkHow Functions Work
How Functions Work
 
Tamarin and ECMAScript 4
Tamarin and ECMAScript 4Tamarin and ECMAScript 4
Tamarin and ECMAScript 4
 
Intro to ES6 and why should you bother !
Intro to ES6 and why should you bother !Intro to ES6 and why should you bother !
Intro to ES6 and why should you bother !
 
Making ES6 available to all with ChakraCore and Typescript
Making ES6 available to all with ChakraCore and TypescriptMaking ES6 available to all with ChakraCore and Typescript
Making ES6 available to all with ChakraCore and Typescript
 
Tamarin And Ecmascript 4
Tamarin And Ecmascript 4Tamarin And Ecmascript 4
Tamarin And Ecmascript 4
 
Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -
 
Modern JavaScript features
Modern JavaScript featuresModern JavaScript features
Modern JavaScript features
 

Último

Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 

Último (20)

Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 

Modern JS with ES6

  • 1. Modern JS with ES6 Kevin Langley Jr.
  • 3. ● May 1995 - Originally developed under the name Mocha. A Brief History
  • 4. ● May 1995 - Originally developed under the name Mocha. ● September 1995 - Released originally as LiveScript. A Brief History
  • 5. ● May 1995 - Originally developed under the name Mocha. ● September 1995 - Released originally as LiveScript. ● December 1995 - Renamed JavaScript with the release of Netscape Navigator 2.0. A Brief History
  • 6. ● May 1995 - Originally developed under the name Mocha. ● September 1995 - Released originally as LiveScript. ● December 1995 - Renamed JavaScript with the release of Netscape Navigator 2.0. ● November 1996 - Netscape submitted JavaScript to Ecma International for standardization. A Brief History
  • 7. ● May 1995 - Originally developed under the name Mocha. ● September 1995 - Released originally as LiveScript. ● December 1995 - Renamed JavaScript with the release of Netscape Navigator 2.0. ● November 1996 - Netscape submitted JavaScript to Ecma International for standardization. ● June 1997 - This resulted in a new language standard, known as ECMAScript. A Brief History
  • 8. ● May 1995 - Originally developed under the name Mocha. ● September 1995 - Released originally as LiveScript. ● December 1995 - Renamed JavaScript with the release of Netscape Navigator 2.0. ● November 1996 - Netscape submitted JavaScript to Ecma International for standardization. ● June 1997 - This resulted in a new language standard, known as ECMAScript. ● ECMAScript is the standard and JavaScript is the most popular implementation of that standard and also builds on top of it. A Brief History
  • 9. ES is short for ECMAScript. Every time you see ES followed by a number, it is referencing an edition of ECMAScript. ES_???
  • 10. ● ES1: June 1997 ES is short for ECMAScript. Every time you see ES followed by a number, it is referencing an edition of ECMAScript. ES_???
  • 11. ● ES1: June 1997 ● ES2: June 1998 ES is short for ECMAScript. Every time you see ES followed by a number, it is referencing an edition of ECMAScript. ES_???
  • 12. ● ES1: June 1997 ● ES2: June 1998 ● ES3: December 1999 ES is short for ECMAScript. Every time you see ES followed by a number, it is referencing an edition of ECMAScript. ES_???
  • 13. ES is short for ECMAScript. Every time you see ES followed by a number, it is referencing an edition of ECMAScript. ES_??? ● ES1: June 1997 ● ES2: June 1998 ● ES3: December 1999 ● ES4: Abandoned
  • 14. ES is short for ECMAScript. Every time you see ES followed by a number, it is referencing an edition of ECMAScript. ES_??? ● ES1: June 1997 ● ES2: June 1998 ● ES3: December 1999 ● ES4: Abandoned ● ES5: December 2009
  • 15. ● ES6/ES2015: June 2015 ES is short for ECMAScript. Every time you see ES followed by a number, it is referencing an edition of ECMAScript. ES_??? ● ES1: June 1997 ● ES2: June 1998 ● ES3: December 1999 ● ES4: Abandoned ● ES5: December 2009
  • 16. ● ES6/ES2015: June 2015 ● ES7/ES2016: June 2016 ES is short for ECMAScript. Every time you see ES followed by a number, it is referencing an edition of ECMAScript. ES_??? ● ES1: June 1997 ● ES2: June 1998 ● ES3: December 1999 ● ES4: Abandoned ● ES5: December 2009
  • 17. ● ES6/ES2015: June 2015 ● ES7/ES2016: June 2016 ● ES8/ES2017: June 2017 ES is short for ECMAScript. Every time you see ES followed by a number, it is referencing an edition of ECMAScript. ES_??? ● ES1: June 1997 ● ES2: June 1998 ● ES3: December 1999 ● ES4: Abandoned ● ES5: December 2009
  • 18. ● ES6/ES2015: June 2015 ● ES7/ES2016: June 2016 ● ES8/ES2017: June 2017 ● ES.Next: This term is dynamic and references the next version of ECMAScript coming out. ES is short for ECMAScript. Every time you see ES followed by a number, it is referencing an edition of ECMAScript. ES_??? ● ES1: June 1997 ● ES2: June 1998 ● ES3: December 1999 ● ES4: Abandoned ● ES5: December 2009
  • 19. The ECMA TC39 committee is responsible for evolving the ECMAScript programming language and authoring the specification. TC39
  • 20. The ECMA TC39 committee is responsible for evolving the ECMAScript programming language and authoring the specification. ● Stage 0 - Strawman TC39
  • 21. The ECMA TC39 committee is responsible for evolving the ECMAScript programming language and authoring the specification. ● Stage 0 - Strawman ● Stage 1 - Proposal TC39
  • 22. The ECMA TC39 committee is responsible for evolving the ECMAScript programming language and authoring the specification. ● Stage 0 - Strawman ● Stage 1 - Proposal ● Stage 2 - Draft TC39
  • 23. The ECMA TC39 committee is responsible for evolving the ECMAScript programming language and authoring the specification. ● Stage 0 - Strawman ● Stage 1 - Proposal ● Stage 2 - Draft ● Stage 3 - Candidate TC39
  • 24. Modules allow you to load code asynchronously and provides a layer of abstraction to your code. ES6 Modules
  • 25. Modules allow you to load code asynchronously and provides a layer of abstraction to your code. Two ways to export from a module. ES6 Modules
  • 26. Modules allow you to load code asynchronously and provides a layer of abstraction to your code. Two ways to export from a module. ● Multiple named exports ES6 Modules
  • 27. Modules allow you to load code asynchronously and provides a layer of abstraction to your code. Two ways to export from a module. ● Multiple named exports ● Single default export ES6 Modules
  • 28. mathlib.js ES6 Modules - Multiple Named Exports
  • 29. function square(x) { return x * x; } mathlib.js ES6 Modules - Multiple Named Exports
  • 30. mathlib.js ES6 Modules - Multiple Named Exports function square(x) { return x * x; } function add(x, y) { return x + y; }
  • 31. mathlib.js ES6 Modules - Multiple Named Exports export function square(x) { return x * x; } export function add(x, y) { return x + y; }
  • 32. mathlib.js ES6 Modules - Multiple Named Exports export function square(x) { return x * x; } export function add(x, y) { return x + y; } main.js
  • 33. mathlib.js ES6 Modules - Multiple Named Exports export function square(x) { return x * x; } export function add(x, y) { return x + y; } main.js console.log(square(9)); // 81 console.log(add(4, 3)); // 7
  • 34. mathlib.js ES6 Modules - Multiple Named Exports export function square(x) { return x * x; } export function add(x, y) { return x + y; } main.js import { square, add } from 'mathlib'; console.log(square(9)); // 81 console.log(add(4, 3)); // 7
  • 35. foo.js ES6 Modules - Single Default Exports
  • 36. foo.js ES6 Modules - Single Default Exports export default function() { console.log('Foo!'); }
  • 37. foo.js ES6 Modules - Single Default Exports export default function() { console.log('Foo!'); } main.js import foo from 'foo'; foo(); // Foo!
  • 41. var is function scoped. var vs let vs const if ( true ) { var foo = 'bar'; } console.log( foo ); // bar let and const are block scoped. if ( true ) { let foo = 'bar'; const bar = 'foo'; } console.log( foo ); console.log( bar ); // ReferenceError. // ReferenceError.
  • 42. let and const let first = 'First string'; { let second = 'Second string'; { let third = 'Third string'; } // Accessing third here would throw a ReferenceError. } // Accessing second here would throw a ReferenceError. // Accessing third here would throw a ReferenceError.
  • 43. let and const const first = 'First string'; { const second = 'Second string'; { const third = 'Third string'; } // Accessing third here would throw a ReferenceError. } // Accessing second here would throw a ReferenceError. // Accessing third here would throw a ReferenceError.
  • 44. Object.freeze() prevents changing the properties. const const foo = { bar: 1 }; foo = 'bar'; // “foo” is read only. foo.bar = 2; console.log(foo); // { bar: 2 } But, you can change the properties! const variables can only be assigned once. It is NOT immutable. const foo2 = Object.freeze(foo); foo2.bar = 3; console.log(foo2.bar); // 2 Object.seal(foo); foo.baz = false; // TypeError Object.seal() prevents changing the object structure.
  • 45. Variable Hoisting Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.
  • 46. Variable Hoisting Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution. Which means you can do this with functions and vars: sayHello(); function sayHello() { console.log('Hello!'); } console.log( foobar ); var foobar = 'Woot!'
  • 47. Variable Hoisting Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution. Which means you can do this with functions and vars: sayHello(); // Hello! function sayHello() { console.log('Hello!'); } console.log( foobar ); // undefined var foobar = 'Woot!'
  • 48. new Thing(); class Thing{}; console.log(foo); let foo = true; console.log(bar); const bar = true; Variable Hoisting In ES6, classes, let, and const variables are hoisted but they are not initialized yet unlike vars and functions.
  • 49. new Thing(); class Thing{}; console.log(foo); let foo = true; console.log(bar); const bar = true; Variable Hoisting In ES6, classes, let, and const variables are hoisted but they are not initialized yet unlike vars and functions. // TypeError // 'foo' was used before it was defined // 'bar' was used before it was defined
  • 50. Temporal Dead Zone The variable is in a temporal dead zone from the start of the block until the initialization is processed. if ( true ) { // TDZ starts! }
  • 51. Temporal Dead Zone The variable is in a temporal dead zone from the start of the block until the initialization is processed. if ( true ) { // TDZ starts! const doSomething = function () { console.log( thing ); // OK! }; }
  • 52. Temporal Dead Zone The variable is in a temporal dead zone from the start of the block until the initialization is processed. if ( true ) { // TDZ starts! const doSomething = function () { console.log( thing ); // OK! }; doSomething(); // ReferenceError }
  • 53. Temporal Dead Zone The variable is in a temporal dead zone from the start of the block until the initialization is processed. if ( true ) { // TDZ starts! const doSomething = function () { console.log( thing ); // OK! }; doSomething(); // ReferenceError let thing = 'test'; // TDZ ends. }
  • 54. Temporal Dead Zone The variable is in a temporal dead zone from the start of the block until the initialization is processed. if ( true ) { // TDZ starts! const doSomething = function () { console.log( thing ); // OK! }; doSomething(); // ReferenceError let thing = 'test'; // TDZ ends. doSomething(); // Called outside TDZ! }
  • 55. But, what should I use?!? var? let? const? The only difference between const and let is that const makes the contract that no rebinding will happen.
  • 56. But, what should I use?!? var? let? const? Mathias Bynens - V8 Engineer @ Google ● Use const by default. ● Only use let if rebinding is needed. ● var shouldn’t be used in ES2015. The only difference between const and let is that const makes the contract that no rebinding will happen.
  • 57. But, what should I use?!? var? let? const? Mathias Bynens - V8 Engineer @ Google ● Use const by default. ● Only use let if rebinding is needed. ● var shouldn’t be used in ES2015. Kyle Simpson - Founder @ Getify Solutions ● Use var for top level variables ● Use let for localized variables in smaller scopes. ● Refactor let to const only after some code has been written and you’re reasonably sure there shouldn’t be variable reassignment. The only difference between const and let is that const makes the contract that no rebinding will happen.
  • 58. Iterables & Looping When using var, you leak a global variable to the parent scope and the variable gets overwritten with every iteration.
  • 59. Iterables & Looping When using var, you leak a global variable to the parent scope and the variable gets overwritten with every iteration. for ( var i = 0; i < 10; i++ ) { setTimeout( function() { console.log( 'Number: ' + i ); }, 1000 ); }
  • 60. // Number: 10 // Number: 10 // Number: 10 // Number: 10 // Number: 10 Iterables & Looping When using var, you leak a global variable to the parent scope and the variable gets overwritten with every iteration. for ( var i = 0; i < 10; i++ ) { setTimeout( function() { console.log( 'Number: ' + i ); }, 1000 ); } // Number: 10 // Number: 10 // Number: 10 // Number: 10 // Number: 10
  • 61. Iterables & Looping Using let in a for loop allows us to have the variable scoped to its block only.
  • 62. Iterables & Looping Using let in a for loop allows us to have the variable scoped to its block only. for ( let i = 0; i < 10; i++ ) { setTimeout( function() { console.log( 'Number: ' + i ); }, 1000 ); }
  • 63. // Number: 0 // Number: 1 // Number: 2 // Number: 3 // Number: 4 Iterables & Looping Using let in a for loop allows us to have the variable scoped to its block only. for ( let i = 0; i < 10; i++ ) { setTimeout( function() { console.log( 'Number: ' + i ); }, 1000 ); } // Number: 5 // Number: 6 // Number: 7 // Number: 8 // Number: 9
  • 64. const iterable = [10, 20, 30]; for (const value of iterable) { console.log(value); } // 10 // 20 // 30 Iterables & Looping ES6 also gives us a new way to loop over iterables!
  • 65. const articleParagraphs = document.querySelectorAll('article > p'); for (const paragraph of articleParagraphs) { paragraph.classList.add('read'); } Iterables & Looping ES6 also gives us a new way to loop over iterables!
  • 66. const foo = 'bar'; for (const letter of foo) { console.log(letter); } // b // a // r Iterables & Looping ES6 also gives us a new way to loop over iterables!
  • 68. // Traditional function expression. const addNumbers = function (num1, num2) { return num1 + num2; } More concise than traditional function expressions: Arrow Functions
  • 69. More concise than traditional function expressions: Arrow Functions // Traditional function expression. const addNumbers = function (num1, num2) { return num1 + num2; } // Arrow function expression. const addNumbers = (num1, num2) => { return num1 + num2; }
  • 70. Arrow functions have implicit returns: Arrow Functions // Traditional function expression. const addNumbers = function (num1, num2) { return num1 + num2; } // Arrow function expression with implicit return. const addNumbers = (num1, num2) => num1 + num2;
  • 71. // Arrow function without any arguments. const sayHello = () => console.log( 'Hello!' ); A few more examples: Arrow Functions
  • 72. // Arrow function without any arguments. const sayHello = () => console.log( 'Hello!' ); // Arrow function with a single argument. const sayHello = name => console.log( `Hello ${name}!` ); A few more examples: Arrow Functions
  • 73. A few more examples: Arrow Functions // Arrow function without any arguments. const sayHello = () => console.log( 'Hello!' ); // Arrow function with a single argument. const sayHello = name => console.log( `Hello ${name}!` ); // Arrow function with multiple arguments. const sayHello = (fName, lName) => console.log( `Hello ${fName} ${lName}!` );
  • 74. function Person(){ this.age = 0; setInterval(function() { this.age++; // `this`refers to the Window. }, 1000); } The value of this is picked up from its surroundings (lexical). Therefore, you don’t need bind(), that, or self anymore! Arrow Functions
  • 75. function Person(){ var that = this; this.age = 0; setInterval(function() { that.age++; // Without arrow functions. Works, but is not ideal. }, 1000); } The value of this is picked up from its surroundings (lexical). Therefore, you don’t need bind(), that, or self anymore! Arrow Functions
  • 76. function Person(){ this.age = 0; setInterval(() => { this.age++; // `this` properly refers to the person object. }, 1000); } The value of this is picked up from its surroundings (lexical). Therefore, you don’t need bind(), that, or self anymore! Arrow Functions
  • 77. const button = document.querySelector('#my-button'); button.addEventListener('click', () => { this.classList.toggle('on'); }) When should I not use arrow functions? Arrow Functions
  • 78. const button = document.querySelector('#my-button'); button.addEventListener('click', () => { this.classList.toggle('on'); // `this`refers to the Window. }) When should I not use arrow functions? Arrow Functions
  • 80. function calculateTotal( subtotal, tax, shipping ) { return subtotal + shipping + (subtotal * tax); } const total = calculateTotal(100, 0.07, 10); Here’s a basic function. Default Arguments
  • 81. function calculateTotal( subtotal, tax, shipping ) { return subtotal + shipping + (subtotal * tax); } const total = calculateTotal(100, 0.07, 10); Let’s add some defaults to the arguments in our function expression! Default Arguments
  • 82. function calculateTotal( subtotal, tax, shipping ) { if ( tax === undefined ) { tax = 0.07; } if ( shipping === undefined ) { shipping = 10; } return subtotal + shipping + (subtotal * tax); } const total = calculateTotal(100); The Old Way Default Arguments
  • 83. function calculateTotal( subtotal, tax, shipping ) { tax = tax || 0.07; shipping = shipping || 10; return subtotal + shipping + (subtotal * tax); } const total = calculateTotal(100); A little better? Default Arguments
  • 84. function calculateTotal( subtotal, tax = 0.07, shipping = 10 ) { return subtotal + shipping + (subtotal * tax); } const total = calculateTotal(100); Now with ES6! Default Arguments
  • 85. function calculateTotal( subtotal, tax = 0.07, shipping = 10 ) { return subtotal + shipping + (subtotal * tax); } const total = calculateTotal(100, , 20); // Can I do this? What if I wanted to only pass in the first and third argument? Default Arguments
  • 86. function calculateTotal( subtotal, tax = 0.07, shipping = 10 ) { return subtotal + shipping + (subtotal * tax); } const total = calculateTotal(100, , 20); // SyntaxError What if I wanted to only pass in the first and third argument? Default Arguments
  • 87. function calculateTotal( subtotal, tax = 0.07, shipping = 10 ) { return subtotal + shipping + (subtotal * tax); } const total = calculateTotal(100, undefined, 20); // What if I wanted to only pass in the first and third argument? Default Arguments
  • 89. const person = { first: 'Kevin', last: 'Langley', location: { city: 'Beverly Hills', state: 'Florida' } }; Destructuring Objects
  • 90. const person = { first: 'Kevin', last: 'Langley', location: { city: 'Beverly Hills', state: 'Florida' } }; const first = person.first; const last = person.last; Destructuring Objects Let’s create some variables from the object properties.
  • 91. const person = { first: 'Kevin', last: 'Langley', location: { city: 'Beverly Hills', state: 'Florida' } }; const { first, last } = person; Destructuring Objects Let’s do that using destructuring.
  • 92. const person = { first: 'Kevin', last: 'Langley', location: { city: 'Beverly Hills', state: 'Florida' } }; const { first, last } = person; const { city, state } = person.location; Destructuring Objects It even works with nested properties.
  • 93. const person = { first: 'Kevin', last: 'Langley', location: { city: 'Beverly Hills', state: 'Florida' } }; const { first: fName, last: lName } = person; const { city: locationCity, state: locationState } = person.location; Destructuring Objects You can also rename the variables from the destructured object!
  • 94. const settings = { color: 'white', height: 500 }; const { width, height, color } = settings; Destructuring Objects What if I tried to destruct a property that doesn’t exist?
  • 95. const settings = { color: 'white', height: 500 }; const { width, height, color } = settings; console.log(width); // undefined console.log(height); // 500 console.log(color); // white Destructuring Objects What if I tried to destruct a property that doesn’t exist?
  • 96. const settings = { color: 'white', height: 500 }; const { width = 200, height = 200, color = 'black' } = settings; Destructuring Objects But, you can set defaults in your destructuring!
  • 97. const settings = { color: 'white', height: 500 }; const { width = 200, height = 200, color = 'black' } = settings; console.log(width); // 200 console.log(height); // 500 console.log(color); // white Destructuring Objects But, you can set defaults in your destructuring!
  • 98. const details = [ 'Kevin', 'Langley', 'kevinlangleyjr.com' ]; Destructuring Arrays You can destructure arrays as well!
  • 99. const details = [ 'Kevin', 'Langley', 'kevinlangleyjr.com' ]; const [ first, last, website ] = details; Destructuring Arrays You can destructure arrays as well!
  • 100. const details = [ 'Kevin', 'Langley', 'kevinlangleyjr.com' ]; const [ first, last, website ] = details; console.log(first); // Kevin console.log(last); // Langley console.log(website); // kevinlangleyjr.com Destructuring Arrays You can destructure arrays as well!
  • 102. function doSomething (x, y, z) { console.log(x, y, z); } let args = [0, 1, 2]; // Call the function, passing args. doSomething.apply(null, args); ...Spread Operator Before ES6, we would run .apply() to pass in an array of arguments.
  • 103. function doSomething (x, y, z) { console.log(x, y, z); } let args = [0, 1, 2]; // Call the function, without `apply`, passing args with the spread operator! doSomething(...args); ...Spread Operator But with ES6, we can use the spread operator ... to pass in the arguments.
  • 104. let array1 = ['one', 'two', 'three']; let array2 = ['four', 'five']; array1.push(...array2) // Adds array2 items to end of array array1.unshift(...array2) //Adds array2 items to beginning of array ...Spread Operator We can also use the spread operator to combine arrays.
  • 105. let array1 = ['two', 'three']; let array2 = ['one', ...array1, 'four', 'five']; console.log(array2); // ["one", "two", "three", "four", "five"] ...Spread Operator We can also use the spread operator to combine arrays at any point.
  • 106. let array1 = [1,2,3]; let array2 = [...array1]; // like array1.slice() array2.push(4) console.log(array1); // [1,2,3] console.log(array2); // [1,2,3,4] ...Spread Operator We can also use the spread operator to create a copy of an array.
  • 107. const players = [ 'Kevin', 'Bobby', 'Nicole', 'Naomi', 'Jim', 'Sherry' ]; const [ first, second, third, ...unplaced ] = players; console.log(first); // Kevin console.log(second); // Bobby console.log(third); // Nicole console.log(unplaced); // ["Naomi", "Jim", "Sherry"] ...Spread Operator We can also use the spread operator with destructuring.
  • 108. const { x, y, ...z } = { x: 1, y: 2, a: 3, b: 4 }; console.log(x); // 1 console.log(y); // 2 console.log(z); // { a: 3, b: 4 } ...Spread Operator We can also use the spread operator with destructuring.
  • 109. const elements = [...document.querySelectorAll('div')]; console.log(elements); // Lists all the div's on the page. ...Spread Operator We can also use the spread operator to expand a NodeList.
  • 110. function doMath(operator, ...numbers) { console.log(operator); // 'add' console.log(numbers); // [1, 2, 3] } doMath('add', 1, 2, 3); ...Rest Operator The rest operator allows us to more easily handle a variable number of function parameters.
  • 112. const name = 'Kevin'; // The old way... console.log('Hello, ' + name + '!'); // Hello, Kevin! Template Literals The Template Literal, introduced in ES6, is a new way to create a string.
  • 113. Template Literals The Template Literal, introduced in ES6, is a new way to create a string. const name = 'Kevin'; // The old way... console.log('Hello, ' + name + '!'); // Hello, Kevin! // With ES6 template literals. console.log(`Hello, ${name}!`); // Hello, Kevin!
  • 114. Template Literals Within template literals you can evaluate expressions. const price = 19.99; const tax = 0.07; const total = `The total price is ${price + (price * tax)}`; console.log(total); // The total price is 21.3893
  • 115. Template Literals With template literals you can more easily create multi-line strings. console.log('This is some text that flows acrossntwo lines!'); // "This is some text that flows across // two lines!" console.log(`But so does this text!`); // "But so does // this text!"
  • 116. New String Methods - .startsWith() const str = 'Learn JavaScript Deeply'; console.log(str.startsWith('Learn')); // true console.log(str.startsWith('JavaScript')); // false console.log(str.startsWith('Deeply', 17)); // true
  • 117. New String Methods - .endsWith() const str = 'Learn JavaScript Deeply'; console.log(str.endsWith('Deeply')); // true console.log(str.endsWith('Learn')); // false console.log(str.endsWith('JavaScript', 16)); // true
  • 118. New String Methods - .includes() const str = 'Learn JavaScript Deeply'; console.log(str.includes('JavaScript')); // true console.log(str.includes('Javascript')); // false console.log(str.includes('PHP')); // false
  • 119. New String Methods - .repeat() const str = 'Deeply'; console.log(str.repeat(3)); // DeeplyDeeplyDeeply console.log(str.repeat(2.5)); // DeeplyDeeply (converts to int) console.log(str.repeat(-1)); // RangeError
  • 121. Enhanced Object Literals const first = 'Kevin'; const last = 'Langley'; const age = 29;
  • 122. Enhanced Object Literals const first = 'Kevin'; const last = 'Langley'; const age = 29; const person = { first: first, last: last, age: age }; Let’s assign our variables to properties of an object!
  • 123. Enhanced Object Literals const first = 'Kevin'; const last = 'Langley'; const age = 29; const person = { first, last, age }; Let’s assign our variables to properties of an object!
  • 124. Enhanced Object Literals const first = 'Kevin'; const last = 'Langley'; const age = 29; const person = { firstName: first, lastName: last, age: age }; Let’s assign our variables to properties of an object!
  • 125. Enhanced Object Literals var obj = { foo: function() { console.log('foo'); }, bar: function() { console.log('bar'); } }; We can also use a shorter syntax for method definitions on objects initializers.
  • 126. Enhanced Object Literals We can also use a shorter syntax for method definitions on objects initializers. const obj = { foo() { console.log('foo'); }, bar() { console.log('bar'); } };
  • 127. Enhanced Object Literals Or even define keys that evaluate on run time inside object literals. let i = 0; const a = { ['foo' + ++i]: i, ['foo' + ++i]: i, ['foo' + ++i]: i }; console.log(a.foo1); // 1 console.log(a.foo2); // 2 console.log(a.foo3); // 3
  • 128. let i = 0; const a = { [`foo${++i}`]: i, [`foo${++i}`]: i, [`foo${++i}`]: i }; console.log(a.foo1); // 1 console.log(a.foo2); // 2 console.log(a.foo3); // 3 Enhanced Object Literals Let’s use template literals for those keys instead!
  • 130. Array.from() const headers = document.querySelectorAll('h1');
  • 131. Array.from() const headers = document.querySelectorAll('h1'); const titles = headers.map(h1 => h1.textContent);
  • 132. Array.from() const headers = document.querySelectorAll('h1'); const titles = headers.map(h1 => h1.textContent); // TypeError: headers.map is not a function
  • 133. Array.from() const headers = document.querySelectorAll('h1'); const headersArray = [...headers]; const titles = headersArray.map(h1 => h1.textContent);
  • 134. Array.from() const headers = document.querySelectorAll('h1'); const headersArray = Array.from(headers); const titles = headersArray.map(h1 => h1.textContent);
  • 135. Array.from() const headers = document.querySelectorAll('h1'); const titles = Array.from(headers, h1 => { return h1.textContent; });
  • 136. Array.from() const titles = Array.from(document.querySelectorAll('h1'), h1 => { return h1.textContent; });
  • 137. Array.from() const headers = Array.from(document.querySelectorAll('h1')); const titles = headers.map(header => header.textContent);
  • 138. Array.from() const headers = document.querySelectorAll('h1'); const titles = Array.from(headers, header => header.textContent);
  • 139. Array.of() const values = Array.of(123, 456, 789);
  • 140. Array.of() const values = Array.of(123, 456, 789); console.log(values);
  • 141. Array.of() const values = Array.of(123, 456, 789); console.log(values); // [123,456,789]
  • 142. Array.find() const posts = [ { id: 1, title: 'Hello World!' }, { id: 2, title: 'Learn JS Deeply!' } ];
  • 143. Array.find() const posts = [ { id: 1, title: 'Hello World!' }, { id: 2, title: 'Learn JS Deeply!' } ];
  • 144. Array.find() const posts = [ { id: 1, title: 'Hello World!' }, { id: 2, title: 'Learn JS Deeply!' } ]; posts.2
  • 145. Array.find() const posts = [ { id: 1, title: 'Hello World!' }, { id: 2, title: 'Learn JS Deeply!' } ]; posts[2]
  • 146. Array.find() const posts = [ { id: 1, title: 'Hello World!' }, { id: 2, title: 'Learn JS Deeply!' } ]; const post = posts.find(post => post.id === 2);
  • 147. Array.find() const posts = [ { id: 1, title: 'Hello World!' }, { id: 2, title: 'Learn JS Deeply!' } ]; const post = posts.find(post => post.id === 2); console.log(post);
  • 148. Array.find() const posts = [ { id: 1, title: 'Hello World!' }, { id: 2, title: 'Learn JS Deeply!' } ]; const post = posts.find(post => post.id === 2); console.log(post); // {id: 2, title: "Learn JS Deeply!"}
  • 149. Array.findIndex() const posts = [ { id: 1, title: 'Hello World!' }, { id: 2, title: 'Learn JS Deeply!' } ]; const post = posts.findIndex(post => post.id === 2);
  • 150. Array.findIndex() const posts = [ { id: 1, title: 'Hello World!' }, { id: 2, title: 'Learn JS Deeply!' } ]; const post = posts.findIndex(post => post.id === 2); console.log(post);
  • 151. Array.findIndex() const posts = [ { id: 1, title: 'Hello World!' }, { id: 2, title: 'Learn JS Deeply!' } ]; const post = posts.findIndex(post => post.id === 2); console.log(post); // 1
  • 153. const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts'); Promises
  • 154. const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts'); console.log(postsPromise); Promises
  • 155. Promises const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts'); console.log(postsPromise); // Promise {<pending>} // __proto__: Promise // [[PromiseStatus]]: "pending" // [[PromiseValue]]: undefined
  • 156. const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts'); Promises
  • 157. const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts'); postsPromise.then(data => console.log(data)); Promises
  • 158. const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts'); postsPromise.then(data => console.log(data)); // Response {type: "cors", url: "https://2018.miami.wordcamp.org/wp- json/wp/v2/posts", redirected: false, status: 200, ok: true, …} Promises
  • 159. const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts'); postsPromise.then(data => data.json()) Promises
  • 160. const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts'); postsPromise.then(data => data.json()).then(data => console.log(data)); Promises
  • 161. const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts'); postsPromise.then(data => data.json()).then(data => console.log(data)); // {id: 5060, date: "2018-03-15T17:41:09", ...} // {id: 4954, date: "2018-03-14T00:21:10", ...} // {id: 4943, date: "2018-03-13T19:16:11", ...} // {id: 4702, date: "2018-03-10T11:04:36", ...} // ... Promises
  • 162. const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts'); postsPromise .then(data => data.json()) .then(data => console.log(data)) Promises
  • 163. const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts'); postsPromise .then(data => data.json()) .then(data => console.log(data)) .catch(err); Promises
  • 164. const postsPromise = fetch('https://2018.miami.wordcamp.org/wp-json/wp/v2/posts'); postsPromise .then(data => data.json()) .then(data => console.log(data)) .catch(err => console.error(err)); Promises
  • 165. const postsPromise = fetch('https://2019.miami.wordcamp.org/wp-json/wp/v2/posts'); postsPromise .then(data => data.json()) .then(data => console.log(data)) .catch(err => console.error(err)); Promises
  • 166. const postsPromise = fetch('https://2019.miami.wordcamp.org/wp-json/wp/v2/posts'); postsPromise .then(data => data.json()) .then(data => console.log(data)) .catch(err => console.error(err)); // TypeError: Failed to fetch Promises
  • 167. const p = new Promise((resolve, reject) => { }); Promises
  • 168. const p = new Promise((resolve, reject) => { resolve(); }); Promises
  • 169. const p = new Promise((resolve, reject) => { reject(); }); Promises
  • 170. const p = new Promise((resolve, reject) => { resolve('Learn JavaScript Deeply!'); }); p.then(data => console.log(data)); Promises
  • 171. const p = new Promise((resolve, reject) => { resolve('Learn JavaScript Deeply!'); }); p.then(data => console.log(data)); // Learn JavaScript Deeply Promises
  • 172. const p = new Promise((resolve, reject) => { reject(Error('Uh oh!')); }); p.then(data => console.log(data)); Promises
  • 173. const p = new Promise((resolve, reject) => { reject(Error('Uh oh!')); }); p.then(data => console.log(data)); // Uncaught (in promise) Error: Uh oh! Promises
  • 174. const p = new Promise((resolve, reject) => { reject(Error('Uh oh!')); }); p .then(data => console.log(data)); .catch(err => console.error(err)); // Error: Uh oh! Promises
  • 176. Classes // Class declaration class Animal { } // Class expression const Animal = class { }
  • 178. class Animal { constructor(name) { this.name = name; } } Classes
  • 179. class Animal { constructor(name) { this.name = name; } speak() { console.log(`${this.name} makes a noise.`); } } Classes
  • 180. class Animal { constructor(name) { this.name = name; } speak() { console.log(`${this.name} makes a noise.`); } } class Dog extends Animal { } Classes
  • 181. class Animal { constructor(name) { this.name = name; } speak() { console.log(`${this.name} makes a noise.`); } } class Dog extends Animal { speak() { console.log(`${this.name} barks!`); } } Classes
  • 182. class Animal { constructor(name) { this.name = name; } speak() { console.log(`${this.name} makes a noise.`); } } class Dog extends Animal { speak() { console.log(`${this.name} barks!`); } } const puppy = new Dog('Spot'); puppy.speak(); // Spot barks! Classes
  • 183. class Animal { constructor(name) { this.name = name; } speak() { console.log(`${this.name} makes a noise.`); } } class Dog extends Animal { constructor(name, breed) { this.breed = breed; } speak() { console.log(`${this.name} barks!`); } } Classes
  • 184. class Animal { constructor(name) { this.name = name; } speak() { console.log(`${this.name} makes a noise.`); } } class Dog extends Animal { constructor(name, breed) { super(name); this.breed = breed; } speak() { console.log(`${this.name} barks!`); } } Classes
  • 186. function resolveAfter(time) { return new Promise(resolve => { }); } Async & Await
  • 187. function resolveAfter(time) { return new Promise(resolve => { setTimeout(() => { }, time); }); } Async & Await
  • 188. function resolveAfter(time) { return new Promise(resolve => { setTimeout(() => { resolve('Resolved after ${time} milliseconds'); }, time); }); } Async & Await
  • 189. function resolveAfter(time) { return new Promise(resolve => { setTimeout(() => { resolve('Resolved after ${time} milliseconds'); }, time); }); } console.log('Starting resolveAfter()'); const result = resolveAfter(500); console.log(result); console.log('Ending resolveAfter()'); // Starting resolveAfter() // Promise {<pending>} // __proto__: Promise // [[PromiseStatus]]: "pending" // [[PromiseValue]]: undefined // Ending resolveAfter() Async & Await
  • 190. async function resolveAfter(time) { return new Promise(resolve => { setTimeout(() => { resolve('Resolved after ${time} milliseconds'); }, time); }); } console.log('Starting resolveAfter()'); const result = await resolveAfter(500); console.log(result); console.log('Ending resolveAfter()'); // SyntaxError: await is only valid in async function Async & Await
  • 191. function resolveAfter(time) { return new Promise(resolve => { setTimeout(() => { resolve('Resolved after ${time} milliseconds'); }, time); }); } async function asyncCall() { console.log('Starting asyncCall()'); const result = await resolveAfter(500); console.log(result); console.log('Ending asyncCall()'); } asyncCall(); Async & Await // 08:14:22.852 Starting asyncCall() // 08:14:23.474 Resolved after 500 milliseconds // 08:14:38.483 Ending asyncCall()
  • 192. function resolveAfter(time) { return new Promise(resolve => { setTimeout(() => { resolve('Resolved after ${time} milliseconds'); }, time); }); } async function asyncCall() { console.log('Starting asyncCall()'); const result1 = await resolveAfter(500); console.log(result1); const result2 = await resolveAfter(5000); console.log(result2); console.log('Ending asyncCall()'); } asyncCall(); // 08:14:22.852 Starting asyncCall() // 08:14:23.474 Resolved after 500 milliseconds // 08:14:28.478 Resolved after 5000 milliseconds // 08:14:38.483 Ending asyncCall() Async & Await
  • 194. ● Generators ● Symbols Features! Features! Features!
  • 195. ● Generators ● Symbols ● Proxies Features! Features! Features!
  • 196. ● Generators ● Symbols ● Proxies ● Sets and WeakSets Features! Features! Features!
  • 197. Features! Features! Features! ● Generators ● Symbols ● Proxies ● Sets and WeakSets ● Maps and WeakMaps
  • 198. Features! Features! Features! ● Generators ● Symbols ● Proxies ● Sets and WeakSets ● Maps and WeakMaps ● And even more that is still in review by TC39!
  • 199. Still have questions? Wes Bos - ES6 for Everyone - http://es6.io

Notas do Editor

  1. Each proposal for an ECMAScript feature goes through the following maturity stages, starting with stage 0. The progression from one stage to the next one must be approved by TC39.
  2. JavaScript has had modules for a long time. However, they were implemented via libraries, not built into the language. ES6 is the first time that JavaScript has built-in modules. These two ways can be mixed, but it is usually better to use them separately.
  3. JavaScript has had modules for a long time. However, they were implemented via libraries, not built into the language. ES6 is the first time that JavaScript has built-in modules. These two ways can be mixed, but it is usually better to use them separately.
  4. JavaScript has had modules for a long time. However, they were implemented via libraries, not built into the language. ES6 is the first time that JavaScript has built-in modules. These two ways can be mixed, but it is usually better to use them separately.
  5. JavaScript has had modules for a long time. However, they were implemented via libraries, not built into the language. ES6 is the first time that JavaScript has built-in modules. These two ways can be mixed, but it is usually better to use them separately.
  6. Babel is one of many JavaScript transpilers available that will convert your edge JavaScript into ES5 JavaScript that is compatible with any browser, even the old ones. With Babel we can use all the syntactical sugar that was added to JavaScript with the new ES6 specification.
  7. Webpack is a static module bundler for modern JS applications. It will recursively build a dependency graph that include every module your application needs, and packs it into bundles.
  8. Referencing the variable in the block before the initialization results in a ReferenceError, contrary to a variable declared with var, which will just have the undefined value and type.
  9. Referencing the variable in the block before the initialization results in a ReferenceError, contrary to a variable declared with var, which will just have the undefined value and type.
  10. Referencing the variable in the block before the initialization results in a ReferenceError, contrary to a variable declared with var, which will just have the undefined value and type.
  11. Referencing the variable in the block before the initialization results in a ReferenceError, contrary to a variable declared with var, which will just have the undefined value and type.
  12. Referencing the variable in the block before the initialization results in a ReferenceError, contrary to a variable declared with var, which will just have the undefined value and type.
  13. Skipped tagged template strings
  14. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  15. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  16. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  17. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  18. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  19. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  20. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  21. Here
  22. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  23. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  24. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  25. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  26. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  27. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  28. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  29. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  30. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  31. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  32. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  33. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  34. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  35. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  36. The Promise object is used for asynchronous operations and represents the eventual completion or failure of that operation, and its resulting value. Promises are often used for fetching data asynchronously.
  37. Behind the scenes, ES6 classes are not something that is radically new. They mainly provide more convenient syntax to create old-school constructor functions.
  38. Behind the scenes, ES6 classes are not something that is radically new. They mainly provide more convenient syntax to create old-school constructor functions.
  39. Behind the scenes, ES6 classes are not something that is radically new. They mainly provide more convenient syntax to create old-school constructor functions.
  40. Behind the scenes, ES6 classes are not something that is radically new. They mainly provide more convenient syntax to create old-school constructor functions.
  41. Behind the scenes, ES6 classes are not something that is radically new. They mainly provide more convenient syntax to create old-school constructor functions.
  42. Behind the scenes, ES6 classes are not something that is radically new. They mainly provide more convenient syntax to create old-school constructor functions.
  43. Behind the scenes, ES6 classes are not something that is radically new. They mainly provide more convenient syntax to create old-school constructor functions.
  44. Behind the scenes, ES6 classes are not something that is radically new. They mainly provide more convenient syntax to create old-school constructor functions.
  45. Behind the scenes, ES6 classes are not something that is radically new. They mainly provide more convenient syntax to create old-school constructor functions.