// 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);
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 refers to the global this
function canMakeHTTPRequest() {
return typeof globalThis.XMLHttpRequest === 'function';
}
console.log(canMakeHTTPRequest()); // true