Skip to content

Latest commit

 

History

History
40 lines (30 loc) · 786 Bytes

5-ES11.md

File metadata and controls

40 lines (30 loc) · 786 Bytes

Dynamic Import

// import just a file
import { max } from '../math.js';
const nums = [1, 2, 3];
max(...nums); // 3
// import a file as a promise: A dynamic import returns a promise. 
const math = '../math.js';
const module = await import(math);
module.max(...numbs);

Promise.allSettled

This is quite similar to Promise.all , but there’s a significant difference between them.

Checks: Promise.all waits for all the promises being "fulfilled" or an any promise being "rejected".

Promise.allSettled wait for all the promises to be "done".


globalThis

// globalThis refers to the global this
function canMakeHTTPRequest() {
  return typeof globalThis.XMLHttpRequest === 'function';
}

console.log(canMakeHTTPRequest()); // true