Logical assignment
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.
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.
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:
Generally, references to objects are strongly held in JavaScript, meaning that as long you have a reference to the object, it won’t be garbage-collected.
const ref = { x: 42, y: 51 };
// As long as you have access to `ref` (or any other reference to the
// same object), the object won’t be garbage-collected.
Currently, WeakMap
s and WeakSet
s are the only way to kind-of-weakly reference an object in JavaScript: adding an object as a key to a WeakMap
or WeakSet
doesn’t prevent it from being garbage-collected.
const wm = new WeakMap();
{
const ref = {};
const metaData = 'foo';
wm.set(ref, metaData);
wm.get(ref);
// → metaData
}
// We no longer have a reference to `ref` in this block scope, so it
// can be garbage-collected now, even though it’s a key in `wm` to
// which we still have access.
Since the introduction of promises in ES2015, JavaScript has supported exactly two promise combinators: the static methods Promise.all
and Promise.race
.
Two new proposals are currently making their way through the standardization process: Promise.allSettled
, and Promise.any
. With those additions, there’ll be a total of four promise combinators in JavaScript, each enabling different use cases.
Large numeric literals are difficult for the human eye to parse quickly, especially when there are lots of repeating digits:
1000000000000
1019436871.42
To improve readability, a new JavaScript language feature enables underscores as separators in numeric literals. So, the above can now be rewritten to group the digits per thousand, for example: