0
0
Typescriptprogramming~5 mins

String manipulation types (Uppercase, Lowercase) in Typescript

Choose your learning style9 modes available
Introduction
Changing text to uppercase or lowercase helps make words look consistent or easier to compare.
When you want to make all letters in a name capital to show importance.
When you need to check if two words are the same without caring about big or small letters.
When you want to show a message in all small letters for style.
When sorting words and you want to ignore letter case differences.
Syntax
Typescript
string.toUpperCase()
string.toLowerCase()
These methods do not change the original string but return a new one.
They work on any string value.
Examples
This example shows how to get uppercase and lowercase versions of a word.
Typescript
const name = "hello";
const upper = name.toUpperCase();
const lower = name.toLowerCase();
Directly changing the case of a string inside console.log.
Typescript
console.log("TypeScript".toUpperCase());
console.log("TypeScript".toLowerCase());
Sample Program
This program changes a greeting to all uppercase and all lowercase, then prints both.
Typescript
const greeting = "Good Morning";

const shout = greeting.toUpperCase();
const whisper = greeting.toLowerCase();

console.log(shout);
console.log(whisper);
OutputSuccess
Important Notes
Remember, strings in TypeScript are not changed by these methods; you get new strings instead.
Use these methods to make text comparisons easier by standardizing letter case.
Summary
Use toUpperCase() to make all letters big.
Use toLowerCase() to make all letters small.
These methods help keep text consistent or easy to compare.