2ality – JavaScript and more

ES proposal: Nullish coalescing for JavaScript

This blog post describes the ECMAScript feature proposal “Nullish coalescing for JavaScript” by Gabriel Isenberg. It proposes the ?? operator that replaces || when it comes to providing default values.

[Read rest of post]


ES proposal: globalThis

The ECMAScript proposal “globalThis” by Jordan Harband provides a new standard way of accessing the global object.

[Read rest of post]


Remainder operator vs. modulo operator (with JavaScript code)


You may have read that JavaScript’s % operator is a remainder operator, not a modulo operator. This blog post explains what that means.

[Read rest of post]


JavaScript Promise combinators: .all(), .race(), .allSettled()

  • Update 2019-08-07: Complete rewrite of section “Overview”.

In this blog post, we take a look at three static methods of Promise:

  • Promise.all() and Promise.race() which JavaScript has had since ECMAScript 6 when Promises were added to the language.
  • Promise.allSettled() which recently advanced to stage 4 and will therefore be part of ECMAScript 2020.
[Read rest of post]


ES proposal: optional chaining

This blog post describes the ECMAScript proposal “Optional chaining” by Gabriel Isenberg, Claude Pache, and Dustin Savery.

[Read rest of post]


ES proposal: private methods and accessors in JavaScript classes

This blog post is part of a series on new members in bodies of class definitions:

  1. Public class fields
  2. Private class fields
  3. Private methods and getter/setters for JavaScript classes

This series replaces 2ality’s prior blog post on fields.


In this blog post, we look at private methods and private accessors (getters and setters) for JavaScript classes. They are a new kind of class member that can’t be accessed outside the body of their class. To understand this post, you should be familiar with private class fields.

This feature is the subject of the ECMAScript proposal “Private methods and getter/setters for JavaScript classes” by Daniel Ehrenberg.

[Read rest of post]


ES proposal: private class fields

This blog post is part of a series on new members in bodies of class definitions:

  1. Public class fields
  2. Private class fields
  3. Private methods and getter/setters for JavaScript classes

This series replaces 2ality’s prior blog post on fields.


In this post, we look at private fields, a new kind of private slot in instances and classes. This feature is part of the ES proposal “Class field declarations for JavaScript” by Daniel Ehrenberg and Jeff Morrison.

[Read rest of post]


Testing static types in TypeScript


Warning: This is experimental work. Read the comments for more information on its limitations.


In this blog post, we’ll examine how we can test static types in TypeScript (inferred types, etc.). For example, given the following function:

function createPoint(x: number, y: number) {
  return {x, y};
}

We’d like to check in a unit test that TypeScript infers this return type:

{x: number, y: number}

In order to do that, we need a few tools that we are going to look at first.

[Read rest of post]


How do JavaScript’s global variables really work?

In this blog post, we examine how JavaScript’s global variables work. Several interesting phenomena play a role: the scope of scripts, the so-called global object, and more.

[Read rest of post]


ES proposal: public class fields

This blog post is part of a series on new members in bodies of class definitions:

  1. Public class fields
  2. Private class fields
  3. Private methods and getter/setters for JavaScript classes

This series replaces 2ality’s prior blog post on fields.


In this post, we look at public fields, which create instance properties and static properties. This feature is part of the ES proposal “Class field declarations for JavaScript” by Daniel Ehrenberg and Jeff Morrison.

[Read rest of post]