ES2018 | 12 New JavaScript Features

Veröffentlicht am: 14 Februar 2018
auf dem Kanal: CodeBig
2,889
34

ES2018 - 12 New JavaScript Features

Code Big Website - https://teamcodebig.com/
Contact us at - contact@teamcodebig.com

 Info
----------------------------------------------------------------------------------------
Title: ES2018 - 12 New JavaScript Features
Level: Intermediate to Advanced
Language: Javascript
Length: 17 minutes
Prerequisites: Basics of JavaScript


// Rest elements for array destructuring assignment:
const primes = [2, 3, 5, 7, 11];
const [first, second, ...rest] = primes;
console.log(first); // 2
console.log(second); // 3
console.log(rest); // [5, 7, 11]

// Spread elements for array literals:
const primesCopy = [first, second, ...rest];
console.log(primesCopy); // [2, 3, 5, 7, 11]

Second code
const dude = {
name: 'Edmond',
age: 30,
role: 'Front End Developer',
}
const {name, ...details} = dude;
console.log(name);
console.log(details);

const details = {
age: 30,
role: 'Front End Developer',
}

const dude = {
name: 'Edmond',
...details
}
console.log(dude);

Third Code
// Shallow-clone an object:
const data = { x: 42, y: 27, label: 'Treasure' };
// The old way:
const clone1 = Object.assign({}, data);
// The new way:
const clone2 = { ...data };


Fourth Code
async function example(){

const arrayOfFetchPromises = [

fetch('https://api.github.com/users/teamCode...,

fetch('https://api.github.com/users/manojsm'),

fetch('https://api.github.com/users/charles')

];

// Regular iterator:
for (const item of arrayOfFetchPromises) {
console.log(item); // Logs a promise
}

//Async Iterator
for await (const item of arrayOfFetchPromises) {
console.log(item);
}

Fifth code
// Note the * after "function"
async function* asyncRandomNumbers() {
// This is a web service that returns a random number
const url = 'https://www.random.org/decimal-fracti...
while (true) {
const response = await fetch(url);
const text = await response.text();
yield Number(text);
}
}

Sixth Code
async function example() {
for await (const number of asyncRandomNumbers()) {
console.log(number);
if (number 0.95) break;
}
}

Seventh Code
fetch('https://api.github.com/users/teamCode...)
.then(response = response.json())
.then(data = console.log(data.name))
.catch(err = console.log(err))
.finally(() = console.log('All fetched'))

Eight code:
function tag (strs) {
" strs[0] === undefined "
" strs.raw[0] === "\\unicode and \\u{55}"; "
}
" tag '\unicode and \u{55}' "

Ninth code
/foo.bar/.test('foo\nbar');
// false
/foo.bar/s.test('foo\nbar');
// true

Tenth code
const re = /(?year\d{4})-(?month\d{2})-(?day\d{2})/u;
const result = re.exec('2019-01-29');
// result.groups.year === '2019';
// result.groups.month === '01';
// result.groups.day === '29';
// result[0] === '2019-01-29';
// result[1] === '2019';
// result[2] === '01';
// result[3] === '29';

Eleventh Code
'$10.53'.match(/(?=\$)\d+(\.\d*)?/)

Tewlth Code
const regexGreekSymbol = /\p{Script=Greek}/u;
regexGreekSymbol.test('π');


Follow us on
---------------------------------------------------------------------------------------
Facebook:   / teamcodebig  
Twitter:   / teamcodebig  
Quora : https://www.quora.com/profile/Manoj-Sm-1
Reddit:   / teamcodebig  
Patreon:   / teamcodebig  
Subscribe:    / @teamcodebig  


Auf dieser Seite können Sie das Online-Video ES2018 | 12 New JavaScript Features mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer CodeBig 14 Februar 2018 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 2,889 Mal angesehen und es wurde von 34 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!