×

typescript · level 1 · unit 3 · lesson 3

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

Strings come with tricks built in.

Every string carries tools with it. A is a tool you use with a dot and brackets. pet.toUpperCase() gives back the string in capitals, and pet.toLowerCase() in small letters.

.trim() cuts spaces off both ends, and .replace("B", "W") swaps the first B for a W. Each one gives back a new string. The box itself stays the same.

A is a fact about a value, read with a dot but no brackets. pet.length tells you how many letters, spaces and symbols the string has.

let pet: string = "Biscuit";
console.log(pet.toUpperCase());
console.log(pet.toLowerCase());
console.log(pet.replace("B", "W"));
console.log(pet.length);
console.log("  hi  ".trim());

Methods need brackets, even empty ones. Properties never have them.