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.

ECMAScript proposal: public class fields

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

In this post, we look at public fields, which create instance properties and static properties.

2019-05

Unpacking hoisting

[2019-05-30] dev, javascript

Quoting a recent tweet by ES6 spec author Allen Wirfs-Brock:

Hoisting is old and confused terminology. Even prior to ES6: did it mean “moved to the top of the current scope” or did it mean “move from a nested block to the closest enclosing function/script scope”? Or both?

This blog post proposes a different approach to describing declarations (inspired by a suggestion by Allen).

2019-04

The new ECMAScript module support in Node.js 12

[2019-04-23] dev, javascript, nodejs, jsmodules

Node.js 12 (which was released on 2019-04-23) brings improved support for ECMAScript modules. It implements phase 2 of the plan that was released late last year. For now, this support is available behind the usual flag --experimental-modules.

Read on to find out how exactly this new support for ECMAScript modules works.

Brief spoiler: The filename extension .mjs will be more convenient, but .js can also be enabled for ES modules.

2019-01

ES2019: JSON superset

[2019-01-29] dev, javascript, es2019, json

The proposal “JSON superset” (by Richard Gibson) is at stage 4 and therefore part of ECMAScript 2019. This blog post explains how it works.

ES2019: String.prototype.trimStart / String.prototype.trimEnd

[2019-01-29] dev, javascript, es2019

The proposal “String.prototype.trimStart / String.prototype.trimEnd” (by Sebastian Markbåge) is at stage 4 and therefore part of ECMAScript 2019. This blog post explains how it works.