Loading video player…

Welcome to the Branch Names That Broke

You’ll learn what a JavaScript string holds, how it becomes bytes, and how regular expressions match Unicode. Your project is a payments team’s branch-name helper, ported from Python.

Here’s a first taste. In Python, a short helper builds a branch name from a ticket’s key and title, and keeps its first 16 characters:

Language: Python
def branch_name(key, title, limit=16):
    name = f"{key}-{title}".lower()
    return name.replace(" ", "-")[:limit]

title = "Zoë's 😀 refund fix"
print(branch_name("PAY-2401", title))

Zoë’s emoji is the 16th character, and Python prints it whole:

Language: Program Output
pay-2401-zoë's-😀

The JavaScript port uses .slice() with the same 16:

Language: JavaScript
function branchName(key, title, limit = 16) {
  const name = `${key}-${title}`.toLowerCase();
  return name.replace(/ /g, "-").slice(0, limit);
}

const title = "Zoë's 😀 refund fix";
console.log(branchName("PAY-2401", title));

The emoji is gone:

Language: Program Output
pay-2401-zoë's-�

In its place, a question mark in a diamond stands in for broken text. The next lesson shows why.

Titles typed in Lisbon and Tokyo give the helper three problems. Zoë’s emoji gets cut. Two café titles that look the same, both for ticket PAY-2402, give two branch names:

Language: Program Output
pay-2402-café-re
pay-2402-café-r

And the team’s git host refuses names over 32 bytes. The team lead’s full Python copes, with len(), unicodedata.normalize() and .encode("utf-8"), and you’ll port that care to JavaScript.

By the end of this course, you’ll be able to:

  • Tell code units from code points, and walk a string by code point with for...of and .codePointAt()
  • Compare look-alike text with .normalize(), and count what a reader sees with Intl.Segmenter
  • Encode text to UTF-8 bytes with TextEncoder, and work with Uint8Array views and copies
  • Match Unicode with the u and v flags, look behind and ahead, and scan with the y flag
  • Rebuild the team’s branch-name helper in JavaScript, matching its Python’s output

In Python, you only need to know str and bytes, encodings, unicodedata.normalize() and re lookarounds. In JavaScript, you only need to know regular expressions with flags and named groups, and iterating with spread and for...of.

You’ll need Node 26 or later installed, and no packages. The examples use Node 26 and Python 3.15.

The course mixes short videos with text lessons and exercises. Every video has a summary below it. A project video rebuilds the helper, and a quiz and a summary close the course.

Next up: Counting What a String Really Holds, where you find out what length counts, and why the emoji broke.

Download

Sample Code (.zip)

14.3 KB
Download

Course Slides (.pdf)

712.3 KB

00:00 Welcome to JavaScript Unicode, Bytes, and Advanced Regular Expressions! You’ll learn what a JavaScript string holds, how it becomes bytes, and how regular expressions match Unicode.

00:11 Your project is a payments team’s branch-name helper, ported from Python. Here’s a first taste. In Python, a short helper builds a branch name from a ticket’s key and title, and keeps sixteen characters.

00:26 The emoji in Zoë’s title is the sixteenth, and Python prints it whole.

00:31 The JavaScript port slices at the same sixteen, and the emoji is gone. In its place, a question mark in a diamond stands in for broken text. The next lesson shows why.

00:45 Titles typed in Lisbon and Tokyo give the helper three problems. Zoë’s emoji gets cut, two café titles that look the same give two branch names, and the host refuses names over 32 bytes.

00:58 The team lead’s full Python copes, with len, normalize and encode, and you’ll port that care to JavaScript.

01:07 You’ll count a string by code unit, code point and grapheme. You’ll normalize and encode text, and match Unicode with regular expressions. Then you’ll rebuild the helper.

01:21 You need to know Python’s strings and bytes, Unicode normalization and regex lookarounds. And JavaScript’s regular expressions and iterators. The examples use Node 26 and Python 3.15.

01:36 Short videos mix with text lessons and exercises, and every video has a summary below it. A quiz and a summary close the course. Next up: Counting What a String Really Holds, where you find out what length counts, and why the emoji broke.

Become a Member to join the conversation.