ES2020 Features!

BigInt

Arbitrary precision integers 📖.

const theBiggestInt = 9007199254740991 n; const alsoHuge = BigInt( 9007199254740991 ); const hugeButString = BigInt( '9007199254740991' );

import

"function-like" import() module loading syntactic. 📖

< nav > < a href = "books.html" data-entry-module = "books" > Books </ a > < a href = "movies.html" data-entry-module = "movies" > Movies </ a > < a href = "video-games.html" data-entry-module = "video-games" > Video Games </ a > </ nav > < main > Content will load here! </ main > < script > const main = document .querySelector( "main" ); for ( const link of document .querySelectorAll( "nav > a" )) { link.addEventListener( "click" , e => { e.preventDefault(); import ( `./section-modules/ ${link.dataset.entryModule} .js` ) .then( module => { module .loadPageInto(main); }) .catch( err => { main.textContent = err.message; }); }); } </ script >

metaproperty for holding host-specific metadata about the current module 📖.

( async () => { const response = await fetch( new URL( "../hamsters.jpg" , import .meta.url)); const blob = await response.blob(); const size = import .meta.scriptElement.dataset.size || 300 ; const image = new Image(); image.src = URL.createObjectURL(blob); image.width = image.height = size; document .body.appendChild(image); })();

nullish coalescing

nullish coalescing operator ?? 📖.

const response = { settings : { nullValue : null , height : 400 , animationDuration : 0 , headerText : '' , showSplashScreen : false } }; const undefinedValue = response.settings.undefinedValue ?? 'some other default' ; const nullValue = response.settings.nullValue ?? 'some other default' ; const headerText = response.settings.headerText ?? 'Hello, world!' ; const animationDuration = response.settings.animationDuration ?? 300 ; const showSplashScreen = response.settings.showSplashScreen ?? true ;

optional chaining

Chaining is now optional 📖.

obj?.prop obj?.[expr] func?.(...args)

All of the promises are settled 📖.

const urls = [ ]; const requests = urls.map( x => fetch(x)); const results = await Promise .allSettled(requests); const successfulPromises = results.filter( p => p.status === 'fulfilled' ); const errors = results .filter( p => p.status === 'rejected' ) .map( p => p.reason);

let regexp = /t(e)(st(\d?))/g ; let str = 'test1test2' ; let array = [...str.matchAll(regexp)]; console .log(array[ 0 ]); console .log(array[ 1 ]);

globalThis

> globalThis <ref * 1 > Object [global] { global : [Circular * 1 ], clearInterval : [ Function : clearInterval], clearTimeout : [ Function : clearTimeout], setInterval : [ Function : setInterval], setTimeout : [ Function : setTimeout] { [ Symbol (nodejs.util.promisify.custom)]: [ Function (anonymous)] }, queueMicrotask : [ Function : queueMicrotask], clearImmediate : [ Function : clearImmediate], setImmediate : [ Function : setImmediate] { [ Symbol (nodejs.util.promisify.custom)]: [ Function (anonymous)] } }

epxort ns from

export ___ from "module" 📖.

export * as ns from "mod" ;

for-in enhancements

For-in enumeration order 📖.