Text, JSON and Tricky Values

Real data is messy: names with extra spaces, a missing phone number, a value that's 0 or empty. Clean up text with string methods, learn which comparisons surprise people, handle missing values safely, and save and load data as JSON.

Updated

Working with Text

  1. String Methods (Apprentice): String methods such as trim, toLowerCase, slice, replaceAll, split, join and padStart tidy and reshape text, and each one hands back a new string while the original stays as it was.

Tricky Values in JavaScript

  1. Equality and Truthy Values (Apprentice): JavaScript has a loose == that converts types before comparing and a strict === that doesn't, and it treats every value as truthy or falsy in a condition, so you learn which to use and where 0 and empty text trip people up.
  2. Missing Values: null, undefined, ?. and ?? (Apprentice): Real data has holes, so learn the difference between undefined and null, read a property that might be missing with ?., and give a missing value a default with ?? instead of ||.

JSON in JavaScript

  1. JSON: Data You Can Save and Send (Apprentice): JSON is the text format the web uses to save and send data, and JSON.stringify and JSON.parse turn your objects and arrays into JSON text and back, as long as the text follows JSON's strict rules.

Exercise: Fun Run Sign-Ups

  1. Exercise: Fun Run Sign-Ups (Apprentice): Finish seven functions that tidy a 5K fun run's messy sign-ups, from names and bib numbers to missing shirt sizes, donations and emergency contacts, and save and load the list as JSON, with tests that check each one.

Up Next: How JavaScript Really Works

  1. Up Next: How JavaScript Really Works (Apprentice): See how much real data you can handle after Module 2, meet the My Music Wrapped project where you'll show it, and get a first look at the ideas Module 3 explains, starting with a function that remembers.