.toUpperCase()
`.toUpperCase()` gives you a new copy of the string with every letter in capitals.
toUpperCase is a string method. You call it with a dot and parentheses: city.toUpperCase(). It takes no arguments.
Strings in JavaScript are immutable: the method does not change the original, it returns a new string. So if you want to keep the result, store it in a variable or use it right away.
In the course you see it in console.log(city.toUpperCase(), year, isLearning): the uppercase version is computed and printed, while city stays the same.
For TypeScript, the method exists only on values of type string. The type checker verifies that before running; when Node runs the code, the types are already gone.
Characters that are not letters, like digits and spaces, stay the same.
Reach for it when: you need to show or compare text in capitals, for example to ignore differences in letter case.
Examples
Common mistake
const name = "ana"; name.toUpperCase(); console.log(name);
Why: The method returns a new string and does not modify `name`. If you do not keep the result, it is lost.
How to write it: Keep the result: const upper = name.toUpperCase(); and use upper.
Common mistake
const year: number = 2024; console.log(year.toUpperCase());
Why: Numbers do not have `toUpperCase`; it only exists on strings.
How to write it: Convert it first with String(year), or use the method only on strings.
