2020-09

ECMAScript 2021

[2020-09-24] dev, javascript, es2021

Update 2021-06-22: The 121st Ecma General Assembly approved the ECMAScript 2021 language specification, which means that it’s officially a standard now.

This blog post describes what’s new.

ECMAScript proposal: Method .item() for Arrays, Typed Arrays, and strings

[2020-09-23] dev, javascript, es proposal

The ECMAScript proposal “.item() (by Shu-yu Guo and Tab Atkins) introduces the mentioned method for indexable values (Arrays, Typed Arrays, strings). Given an index, the method returns the corresponding element. Its key benefit is that indices can be negative (-1 gets the last element, -2 the second last, etc.). This blog post examines .item() in detail.

Update November 2020: The method name .item() ended up not being web-compatible. The tentative new name is .at().

2020-08

Minimal React: getting started with the frontend library

[2020-08-25] dev, javascript, frontend, react

This blog post explains how to get started with React while using as few libraries as possible.

2020-07

Eliminating duplicate objects: three approaches

[2020-07-17] dev, javascript

In this blog post, we look at three approaches for eliminating duplicate objects from Arrays.

2020-06

ECMAScript proposal: private static methods and accessors in classes

[2020-06-24] dev, javascript, es proposal, js classes

This post explains private static methods and accessors in classes, as described in the ECMAScript proposal “Static class features” by Shu-yu Guo and Daniel Ehrenberg.

Computing with types in TypeScript

[2020-06-15] dev, javascript, typescript

In this blog post, we explore how we can compute with types at compile time in TypeScript.

Note that the focus of this post is on learning how to compute with types. Therefore, we’ll use literal types a lot and the examples are less practically relevant. Future blog posts will cover real-world use cases.

ES2021: Logical assignment operators

[2020-06-11] dev, javascript, es2021

The ECMAScript proposal “Logical assignment operators” (by Justin Ridgewell and Hemanth HM) introduces the following compound assignment operators:

  • a ||= b
  • a &&= b
  • a ??= b

TypeScript: validating external data

[2020-06-09] dev, javascript, typescript

Data validation means ensuring that data has the desired structure and content.

With TypeScript, validation becomes relevant when we receive external data such as:

  • Data parsed from JSON files
  • Data received from web services

In these cases, we expect the data to fit static types we have, but we can’t be sure. Contrast that with data we create ourselves, where TypeScript continuously checks that everything is correct.

This blog post explains how to validate external data in TypeScript.

TypeScript: narrowing types via type guards and assertion functions

[2020-06-07] dev, javascript, typescript

In TypeScript, a value can have a type that is too general for some operations – for example, a union type. This blog post answers the following questions:

  • What is narrowing of types?
    • (Spoiler: focusing on a subset of an overly general type, in a specific region of a program)
  • What are type guards and assertion functions and how can we use them to narrow types?

Type assertions in TypeScript

[2020-06-06] dev, javascript, typescript

This blog post is about type assertions in TypeScript, which are related to type casts in other languages and performed via the as operator.