🎓 Top 15 Udemy Courses (80-90% Discount): My Udemy Courses - Ramesh Fadatare — All my Udemy courses are real-time and project oriented courses.
▶️ Subscribe to My YouTube Channel (178K+ subscribers): Java Guides on YouTube
▶️ For AI, ChatGPT, Web, Tech, and Generative AI, subscribe to another channel: Ramesh Fadatare on YouTube
In this chapter, we will explore the toLowerCase() method in TypeScript. This method is a built-in function that helps in converting all the characters in a string to lowercase. Understanding how to use toLowerCase() is useful for standardizing string cases and performing case-insensitive comparisons.
Table of Contents
- Definition
- Syntax
- Examples
- Conclusion
1. Definition
The toLowerCase() method returns the calling string value converted to lowercase. This method does not affect the original string but returns a new string with all lowercase characters.
2. Syntax
string.toLowerCase();
Parameters
The toLowerCase() method does not take any parameters.
Return Value
The method returns a new string representing the calling string converted to lowercase.
3. Examples
Let's look at some examples to understand how toLowerCase() works in TypeScript.
Example 1: Basic Usage
In this example, we convert a string to lowercase.
let str: string = "Hello, TypeScript!";
let result = str.toLowerCase();
console.log(result); // Output: hello, typescript!
Example 2: Mixed Case String
In this example, we convert a string with mixed case characters to lowercase.
let str: string = "TypeScript Is Awesome!";
let result = str.toLowerCase();
console.log(result); // Output: typescript is awesome!
Example 3: String with Numbers and Symbols
In this example, we convert a string containing numbers and symbols to lowercase. Note that numbers and symbols are unaffected by the toLowerCase() method.
let str: string = "123 ABC! @#";
let result = str.toLowerCase();
console.log(result); // Output: 123 abc! @#
Example 4: Using toLowerCase() for Case-Insensitive Comparison
In this example, we use toLowerCase() to perform a case-insensitive comparison between two strings.
let str1: string = "TypeScript";
let str2: string = "typescript";
if (str1.toLowerCase() === str2.toLowerCase()) {
console.log("The strings are equal (case-insensitive).");
} else {
console.log("The strings are not equal.");
}
// Output: The strings are equal (case-insensitive).
4. Conclusion
In this chapter, we explored the toLowerCase() method in TypeScript, which is used to convert all the characters in a string to lowercase. We covered its definition, syntax, parameters, return value, and provided several examples to demonstrate its usage. Understanding how to use toLowerCase() effectively can help in various string manipulation tasks in TypeScript, especially when standardizing string cases and performing case-insensitive comparisons.
My Top and Bestseller Udemy Courses. The sale is going on with a 70 - 80% discount. The discount coupon has been added to each course below:
Build REST APIs with Spring Boot 4, Spring Security 7, and JWT
[NEW] Learn Apache Maven with IntelliJ IDEA and Java 25
ChatGPT + Generative AI + Prompt Engineering for Beginners
Spring 7 and Spring Boot 4 for Beginners (Includes 8 Projects)
Available in Udemy for Business
Building Real-Time REST APIs with Spring Boot - Blog App
Available in Udemy for Business
Building Microservices with Spring Boot and Spring Cloud
Available in Udemy for Business
Java Full-Stack Developer Course with Spring Boot and React JS
Available in Udemy for Business
Build 5 Spring Boot Projects with Java: Line-by-Line Coding
Testing Spring Boot Application with JUnit and Mockito
Available in Udemy for Business
Spring Boot Thymeleaf Real-Time Web Application - Blog App
Available in Udemy for Business
Master Spring Data JPA with Hibernate
Available in Udemy for Business
Spring Boot + Apache Kafka Course - The Practical Guide
Available in Udemy for Business
Comments
Post a Comment
Leave Comment