Strings, Numbers, Dates and Regex

The data types every application actually formats and parses. Slice and build strings without fighting immutability, write tagged templates that escape for you, round money without losing a cent, read a regular expression out loud, survive the Date API, and hand formatting over to Intl instead of hand rolling it.

What you will be able to do

  • Reach for the right string method first time, and know which ones lie about unicode
  • Write a tagged template that escapes untrusted values automatically
  • Round, clamp and compare numbers without floating point surprises
  • Read, write and debug a regular expression, including named groups and lookaround
  • Do date arithmetic that survives month ends, leap years and time zones
  • Format numbers, dates, lists and plurals with Intl instead of hand written tables

Lessons

  1. String Methods Mastery — A string is a frozen array of UTF-16 code units. Every method that looks like it edits one is really handing you a brand new string. (14 min)
  2. Template Literals and Tagged Templates — A template literal is a string with holes. A tagged template hands you the pieces and the hole contents separately, so you can decide what goes in each hole. (13 min)
  3. Math and Numbers — Every JavaScript number is a 64-bit float pretending to be a decimal. Round on the way out, never on the way in, and count money in whole pennies. (15 min)
  4. Regular Expressions — A regex is a tiny program that walks a string one character at a time and backtracks when it guesses wrong. Read it out loud and you can debug it. (18 min)
  5. Dates with Date — A Date holds one number: milliseconds since 1970 in UTC. Everything else, including the month you read back, is a rendering of that number in some time zone. (15 min)
  6. Temporal — Temporal makes you say what kind of time you mean. A date with no time, a time with no date, an exact instant, or a wall clock reading in a named zone: four types, so the ambiguity is gone before the arithmetic starts. (14 min)
  7. Internationalisation — Intl is a formatting service that already knows every locale. Your job is to hand it a number, a date or a list, and never to build the string yourself. (15 min)