Import assertions
The new import assertions feature allows module import statements to include additional information alongside the module specifier. An initial use for the feature is to enable JSON documents to be imported as JSON modules:
The new import assertions feature allows module import statements to include additional information alongside the module specifier. An initial use for the feature is to enable JSON documents to be imported as JSON modules:
The in
operator can be used for testing whether the given object (or any object in its prototype chain) has the given property:
const o1 = {'foo': 0};
console.log('foo' in o1); // true
const o2 = {};
console.log('foo' in o2); // false
const o3 = Object.create(o1);
console.log('foo' in o3); // true
The private brand checks feature extends the in
operator to support private class fields:
class A {
static test(obj) {
console.log(#foo in obj);
}
#foo = 0;
}
A.test(new A()); // true
A.test({}); // false
class B {
#foo = 0;
}
A.test(new B()); // false; it's not the same #foo
Since private names are only available inside the class which defines them, the test must also occur inside the class, for example in a method like static test
above.
Subclass instances receive private fields from the parent class as own-properties:
class SubA extends A {};
A.test(new SubA()); // true
But objects created with with Object.create
(or that have the prototype set later via the __proto__
setter or Object.setPrototypeOf
) don't receive the private fields as own-properties. Because private field lookup only works on own-properties, the in
operator does not find these inherited fields:
The new class static initialization block syntax lets developers gather code that should run once for a given class definition and put them in a single place. Consider the following example where a pseudo-random number generator uses a static block to initialize an entropy pool once, when the class MyPRNG
definition is evaluated.
The JS-BigInt-Integration feature makes it easy to pass 64-bit integers between JavaScript and WebAssembly. This post explains what that means and why it’s useful, which includes making things simpler for developers, letting code run more quickly, and also speeding up build times.
Atomics.wait
and Atomics.notify
are low-level synchronization primitives useful for implementing mutexes and other means of synchronization. However, since Atomics.wait
is blocking, it’s not possible to call it on the main thread (trying to do so throws a TypeError
).
JavaScript supports a range of compound assignment operators that let programmers succinctly express a binary operation together with assignment. Currently, only mathematical or bitwise operations are supported.
Web applications that reach a global audience need to show the display names of languages, regions, scripts, and currencies in many different languages. The translations of those names require data, which is available in the Unicode CLDR. Packaging the data as part of the application incurs a cost on developer time. Users are likely to prefer consistent translations of language and region names, and keeping that data up to date with the world's geopolitical happenings requires constant maintenance.
SIMD stands for Single Instruction, Multiple Data. SIMD instructions are a special class of instructions that exploit data parallelism in applications by simultaneously performing the same operation on multiple data elements. Compute intensive applications like audio/video codecs, image processors, are all examples of applications that take advantage of SIMD instructions to accelerate performance. Most modern architectures support some variants of SIMD instructions.
JavaScript is now equipped with a new regular expression enhancement, called “match indices”. Imagine you want to find invalid variable names in JavaScript code that coincide with reserved words, and output a caret and an “underline” under the variable name, like:
If you’ve ever dealt with strings in JavaScript, chances are you came across the String#replace
method. String.prototype.replace(searchValue, replacement)
returns a string with some matches replaced, based on the parameters you specify: