Converting a string to lower case

TypeScript:
Converting a string to lower case

How to:

In TypeScript, making a string lowercase is a piece of cake. Just call .toLowerCase() on your string. Here’s how:

let myString: string = "HeLLo, WorLD!";
let lowerCaseString: string = myString.toLowerCase();
console.log(lowerCaseString); // Output: "hello, world!"

Easy, eh?

Deep Dive

Back in the day, text processing wasn’t always consistent, and character encoding could be a wild west. Now, with Unicode and standardized methods, cases are uniform across languages. Compared to .toLowerCase(), an old-school approach (like ASCII manipulation) is stone-age. Alternatives (like .toLocaleLowerCase()) consider locale-specific rules for proper casing, which can be handy. Under the hood, .toLowerCase() in JavaScript (and TypeScript by extension) goes through each character and, if it’s an uppercase letter, transforms it to its lower-case equivalent based on Unicode mappings.

See Also

For more string gymnastics and to spice up your text-processing game, give these a look: