Home & blog

Tag: javascript

JavaScript maps and sets part 3: Sets

11 Jan 2021 javascript

In the third and final part of my three-part series on maps and sets, we'll be looking at sets and weak sets, and see how they're similar to, but also different from, traditional arrays.

JavaScript maps and sets part 2: Weak maps

1 Jan 2021 javascript

In part two of this in-depth guide to JavaScript maps and sets we'll be looking at the weird, exotic world of weak maps. These are like maps, except the keys are always objects and the entries are "weakly held". We'll explore just what this means.

JavaScript maps and sets part 1: Maps

15 Dec 2020 javascript

In this guide we'll be looking at JavaScript maps and sets. First up, maps, which are a sort of super object. They work like objects, but with some key differences and improvements - most notably, they have a reliable order and can accesspt any data type as keys!

Event delegation in JavaScript

1 Nov 2020 javascript

Event delegation is a great pattern to learn in JavaScript - yet it's still alien to many beginner/intermediate developers. Let's see how it works, and why you need to be using it. We'll even make our own jQuery-style on() method.

Introducing Promice.any()

2 Aug 2020 javascript

Meet Promise.any(), which is supported by the just-released Firefox 79. It's like Promise.race(), except it listens only for the first promise to be fulfilled, not merely resolved either way.

Pairing two identical arrays, avoiding duplicates

19 Jun 2020 javascript

I recently answered a question on Stack Overflow where the OP had two identical arrays, and wished to pair them, but avoiding duplicates. Turned out to be a bit of a brain burner, so I thought I'd post up my approach here.

Querying and transforming JSON with J-Path

2 Jun 2020 javascript

It's common to want to transform flat JSON into a nested structure. With XML, we can do this easily with XPath. But what about JSON? In this article I'll be demonstrating this using my own J-Path and JavaScript sets.

A simple way to sort HTML lists / localeCompare()

11 Apr 2020 javascript

Since the dawn of time people have been asking how to sort HTML elements - usually lists or tables. Back in the day we had jQuery plugins for this (including one from yours truly). Let's look at an elegant, native approach.

Adventures with the Clipboard API

22 Mar 2020 javascript

If you allow a user to paste input, how do you sanitise the clipboard data? What if it's been copied from something obscure and comes laden with styling tags? Let's see how we can remove them.

Resolving ES6 promises from outside

16 Feb 2020 javascript

When the JavaScript Promises specification was released, one of the first questions that got asked (and is still asked) was: but how do I resolve them from outside, a la jQuery deferred objects? That's not how they're intended to work, but it is possible.

How relevant is jQuery in 2020?

8 Jan 2020 javascript

jQuery took the world by storm. It filled in the gaps of JavaScript's then rather sparse API, and made coding MUCH simpler. But the JavaScript API has moved on, and reactive frameworks are the naem of the game. How relevant still is jQuery?

JavaScript aync/await part 1: how we got here

13 Oct 2019 javascript

ECMAScript 2016's async/await combo really was a game-changer when it comes to writing shallow, synchronous-looking code that hides away asynchronous operations, and they really took promises to a new level. Let's meet them!

JavaScript Promises part 1: Meet promises

31 Jul 2019 javascript

Promises a great way to write shallow, readable code that looks synchronous but actually hides away asynchronous operations. In this first of three articles I'll be showing you how they work, and what problem they solve.

JavaScript Promises part 3: Wrapping up

28 Jun 2019 javascript

Rounding off this three-part series on JavaScript promises, in this article we'll look at promise events, combining promises with ECMAScript 2017's async/await combo, plus some of the standard APIs that use or depend on promises.

JavaScript generators part 3: Yet more generators

31 Mar 2019 javascript

Wrapping up my three-part guide to JavaScript generators, in this article we'll take a look at how generators compare with the later async/await combo, with which they share much in common, and also see how generators can delegate tasks to other generators.

JavaScript generators part 1: Generator basics

25 Feb 2019 javascript

Welcome to JavaScript generators! In this article, the first in a three-part guide, I'm going to be introducing the basics of genereator functions, what they're about, how you can use them and give a hint to their deeper capabilities that we'll meet later in the series.

JavaScript iterators and iterables

1 May 2018 javascript

In this article I'll be taking a look at JavaScript iterables, iterators, and the two protocols that govern them. Iterators control how an object can be iterated over, while an iterable can be fed to constructs such as for-of or spread syntax.