Skip to content

MylesBorins/i-love-this-pattern

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

I <3 this pattern

I really do

What are the features I'm using that I love?

  • Destructuring
  • Rest Paramaters
  • Async Functions and Await
  • Await Promise.all!!!

Destructuring

mdn

const { readFile } = require('fs').promises
const { resolve } = require('path');

Rest Parameters

mdn

function sum(...numbers) {
  return numbers.reduce((total, num) => total + num, 0);
}

sum(1);
// 1
sum(1, 1);
// 2
sum(1, 1, 2);
// 4
sum(1, 1, 2, 3);
// 7
sum(1, 1, 2, 3, 5);
// 12

Why use this instead of arguments?

Did you notice that numbers has the Array.prototype methods πŸŽ‰

Async Functions and Await

mdn

async function latestCurrentNode () {
  const response = await fetch('https://nodejs.org/download/release/index.tab');
  const tab = await response.text();
  const [version, date] = tab.split('\n')[1].split('\t');
  console.log(`The latest release of node is ${version}.\nIt was released on ${date}.`);
}

latestCurrentNode().catch(console.log);

Await Promise.all

mdn

See index.js πŸ˜‰

About

Modern JavaScript is fun πŸŽ‰

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published