Created
August 21, 2020 17:32
-
-
Save hermesespinola/4721927acaeea352e4d727afc3109539 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* ! Babel plugins | |
* * @babel/plugin-proposal-nullish-coalescing-operator | |
* * @babel/plugin-proposal-optional-chaining | |
* * @babel/plugin-proposal-class-properties | |
* * @babel/plugin-proposal-private-methods | |
* * @babel/plugin-syntax-bigin | |
*/ | |
// ! Private class variables | |
class Message { | |
#message = "howdy"; | |
greet() { | |
console.log(this.#message); | |
} | |
} | |
const greeting = new Message(); | |
greeting.greet(); | |
console.log(greeting.#message); // Private name #message is not defined | |
// ! Promise.allSettled | |
const p1 = new Promise((res, rej) => setTimeout(res, 1000)); | |
const p2 = new Promise((res, rej) => setTimeout(rej, 1000)); | |
Promise.allSettled([p1, p2]).then(data => console.log(data)); | |
// [ | |
// Object { status: "fulfilled", value: undefined}, | |
// Object { status: "rejected", reason: undefined} | |
// ] | |
// ! Nullish Coalescing Operator | |
let person = { | |
profile: { | |
name: "", | |
age: 0 | |
} | |
}; | |
// coalescing | |
console.log(person.profile.name ?? "Anonymous"); // "" | |
console.log(person.profile.age ?? 18); // 0 | |
// Or expression | |
console.log(person.profile.name || "Anonymous"); // Anonymous | |
console.log(person.profile.[age] || 18); // 18 | |
// ! Optional Chaining Operator | |
let person = {}; | |
// console.log(person.profile.name ?? "Anonymous"); // person.profile is undefined | |
console.log(person?.profile?.name ?? "Anonymous"); // Anonymous | |
console.log(person?.profile?.age ?? 18); // 18 | |
// ! BigInt | |
// Normal integers | |
const max = Number.MAX_SAFE_INTEGER; | |
console.log(max); // 9007199254740991 | |
console.log(max + 1); // 9007199254740992 | |
console.log(max + 2); // 9007199254740992 | |
console.log(max + 3); // 9007199254740994 | |
console.log(Math.pow(2, 53) == Math.pow(2, 53) + 1); // true | |
const bigNum = 100000000000000000000000000000n; | |
console.log(bigNum * 2n); // 200000000000000000000000000000n | |
// ! Dynamic Import | |
// Why dynamic imports? | |
// * they are not limited to the top level of the file | |
// * they can be loaded conditionally (inside an if) | |
// * the name of the package can be determined at execution time | |
const doMath = async (num1, num2) => { | |
if (num1 && num2) { | |
const math = (await import('./math.js')).default; | |
console.log(math); | |
console.log(math.add(5, 10)); | |
} else { | |
console.log('2 nums req'); | |
} | |
}; | |
doMath(4, 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment