2022-03

First look: adding type annotations to JavaScript

[2022-03-09] dev, javascript, es proposal

The ECMAScript proposal “Types as comments” (by Gil Tayar, Daniel Rosenwasser, Romulo Cintra, Rob Palmer, and others) is about adding type annotations to JavaScript (there is also an accompanying blog post).

Such type annotations would look similar to TypeScript’s and Flow’s annotations and are completely ignored at runtime.

In this blog post, I briefly explain how the proposed type annotations would work and then describe what I think about them.

JavaScript naming conflicts: How existing code can force proposed features to be renamed

[2022-03-07] dev, javascript, jslang

Sometimes the name of a proposed feature (a method, a global variable, etc.) clashes with existing code and has to be changed. This blog post explains how that can happen and lists features that were renamed.

How do primitive values get their properties?

[2022-03-02] dev, javascript, jslang

JavaScript has two kinds of values:

  • primitive values (undefined, null, booleans, numbers, bigints, strings, symbols)
  • objects (all other values)

The ECMAScript specification states:

A primitive value is a datum that is represented directly at the lowest level of the language implementation.

However, despite this fact, we can still use primitive values (other than undefined and null) as if they were immutable objects:

> 'xy'.length
2

This blog post answers the following question:

How do primitive values get their properties?

We’ll look at:

  • Getting property values
  • Invoking property values (a.k.a. method calls)
  • Setting property values

Each time, we’ll first examine what’s going on via JavaScript code and then investigate how the language specification explains the phenomena.

Note that JavaScript engines only mimick the external behavior of the language specification. Some of what the spec does internally is not very efficient (e.g. wrapping primitive values) and often done differently in engines.

2022-02

What are wrapper objects for primitive values?

[2022-02-20] dev, javascript, jslang

Each of the primitive types boolean, number, bigint, string and symbol has an associated wrapper class (Boolean, Number, BigInt, String, Symbol). In this blog post, we examine what these classes are good for.

2022-01

A pipe operator for JavaScript: introduction and use cases

[2022-01-27] dev, javascript, es proposal

The proposal “Pipe operator (|>) for JavaScript” (by J. S. Choi, James DiGioia, Ron Buckton and Tab Atkins) introduces a new operator. This operator is an idea borrowed from functional programming that makes applying functions more convenient in many cases.

This blog post describes how the pipe operator works and what its use cases are (there are more than you might expect!).

Setting up symbol-valued constants via proxies

[2022-01-26] dev, javascript, proxy

Dean Tribble (via Rob Palmer) has come up with a neat trick to create constants whose values are strings with their names. With a minor change, we can use it to set up symbol-valued constants.

ECMAScript proposal: grouping Arrays via .group() and .groupToMap()

[2022-01-21] dev, javascript, es proposal

This blog post describes the ECMAScript proposal “Array grouping” by Justin Ridgewell.

structuredClone(): deeply copying objects in JavaScript

[2022-01-16] dev, javascript, jslang

Spreading is a common technique for copying objects in JavaScript:

Spreading has one significant downside – it creates shallow copies: The top levels are copied, but property values are shared.

structuredClone() is a new function that will soon be supported by most browsers, Node.js and Deno. It creates deep copies of objects. This blog post explains how it works.

Publishing and consuming ECMAScript modules via packages – the big picture

[2022-01-12] dev, javascript, esm

The ecosystem around delivering ECMAScript modules via packages is slowly maturing. This blog post explains how the various pieces fit together:

  • Packages – JavaScript’s units for software distribution
  • The three kinds of ECMAScript module specifiers
  • Providing and using packages via module specifiers in Node.js, Deno and web browsers

2021-12

New in Node.js: node: protocol imports

[2021-12-12] dev, javascript, nodejs

Node.js now supports a node: protocol for built-in modules.