2019-10

Evaluating JavaScript code via import()

[2019-10-01] dev, javascript

The import() operator lets us dynamically load ECMAScript modules. But they can also be used to evaluate JavaScript code (as Andrea Giammarchi recently pointed out to me), as an alternative to eval(). This blog post explains how that works.

2019-08

ES2020: Nullish coalescing for JavaScript

[2019-08-19] dev, javascript, es feature, es2020

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.

ES feature: globalThis

[2019-08-07] dev, javascript, es feature, es2020

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

Remainder operator vs. modulo operator (with JavaScript code)

[2019-08-05] dev, javascript

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

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

[2019-08-04] dev, javascript, es feature, es2020, promises

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.

2019-07

ES2020: optional chaining

[2019-07-28] dev, javascript, es feature, es2020

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

ECMAScript proposal: private prototype methods and accessors in classes

[2019-07-22] dev, javascript, es proposal, js classes

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 and Kevin Gibbons.

ECMAScript proposal: private class fields

[2019-07-17] dev, javascript, es proposal, js classes

In this post, we look at private fields, a new kind of private slot in instances and classes. This feature is specified by two ECMAScript proposals:

Testing static types in TypeScript

[2019-07-11] dev, 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.

How do JavaScript’s global variables really work?

[2019-07-07] dev, javascript, es feature

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.