I really do
- Destructuring
- Rest Paramaters
- Async Functions and Await
- Await Promise.all!!!
const { readFile } = require('fs').promises
const { resolve } = require('path');
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
Did you notice that numbers
has the Array.prototype
methods 🎉
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);
See index.js 😉