New method added to the String prototype. If we have a string and a regular expression, the matchAll() method returns an iterator of all results matching a string against the provided regular expression, also the capturing groups.
Dynamic imports allows us to import JS files dynamically as modules in the application.
This feature will help us access some on-demand-request code, without taking the heat of importing all the dependencies which could be a waste of resources. We can also conditionally load code in an if-else block or async-await.
So, we only import a module when and where required without polluting the global namespace.
Anything beyond the MAX_SAFE_INTEGER starts acting funny. Let’s take a look:
Promise.allSettled() returns a promise that is fulfilled with an array of promise state objects, but only after all the original promises have settled, i.e. become either fulfilled or rejected.In contrast to Promise.all() or Promise.race() added in ES2015, which short-circuits when any of the promises are rejected or settled respectively, Promise.allSettled runs all promises without regard to rejection of any promises.
Well the above tweet from Daniel Ehrenberg inspired Jordan harband to propose globalThis.
So until now, we would make our own implementation of detecting runtime and then using the correct global.
Now, we can use globalThis which always refers to the global object, no matter where the code is executed:
The ECMA-262 has no specification about the order in which the for(key in Obj) should run. Major browsers have implemented a consistent order on their own till now.
Here are some test cases from before this was a concrete proposal:
You can find more such test cases here. Now, the different engines have agreed on how properties are iterated when using the for (key in Obj) control structure so that the behavior is standardized in ES2020.
If we want to access a property value that’s deep in a tree-like structure, we usually check whether it exists or not.
In other cases, many API return either an object or null/undefined, and we may want to obtain a property value from the response object only when it is not null.The Optional Chaining Operator helps us to handle such cases.
Nullish coalescing Operator
When performing property accesses, it is often desired to provide a default value if the result of that property access is null or undefined.
Let’s assume we have the following object:
But in other cases it can mess up your logic implementation:
The nullary coalescing operator is intended to handle these cases better and serves as an equality check against nullary values (null or undefined).
The last on the list is import.meta which is still in stage3 of the TC39 process (at the time this was written).When we are working with a module, we are concerned what’s in it. We need information about the module – its metadata. An example of module metadata for Node.js modules: the global variable __dirname which contains the path of the directory in which the current module is stored.
ES2020 will introduce the pseudo-property import.meta which holds an object with metadata for the current module.
The syntax consists of the keyword import, a dot, and the identifier meta. But here import is not an object.
The import.meta object is created with a null prototype. The object is extensible, and its properties are writable, configurable, and enumerable.