- 1 current stop: learning
- 2 upcoming
- 3 upcoming
- 4 upcoming
- 5 upcoming
Finish after stop 5
Stop 1 of 5 · Loading dock: weighing the parcels
Trick to keep in mind+3 XP
Characters are what you read; bytes are what you ship. Count the right one.
A string counts characters, a Buffer counts bytes, and UTF-8 spends 1 byte on plain ASCII but 2 on many accented letters and 3 on symbols like the euro sign. So any text with non-ASCII characters has a byte length larger than its length. Work out each character's width, then add up.
const s = "café €";
console.log(s.length, Buffer.byteLength(s));
// 6 9Read it once, then a question tests whether the trick stuck.