Open In App

TypeScript String toLowerCase() Method

Last Updated : 15 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

The toLowerCase() method in TypeScript is a built-in function used to convert all characters within a string to lowercase. This method is essential when normalizing strings for comparisons, ensuring consistency in data processing.

Syntax

string.toLowerCase( ) 

Parameter

  • The toLowerCase() method does not accept any parameters.

Return Value

  • This method returns a new string with all the characters converted to lowercase.

Examples of TypeScript String toLowerCase() Method

Example 1: Basic Conversion

Convert a simple string to lowercase.

Example : 

TypeScript
    // Original strings
    var str = "Geeksforgeeks - Best Platform"; 

    // use of String toLowerCase() Method
    var newstr = str.toLowerCase() 
    console.log(newstr);

Output: 

geeksforgeeks - best platform

Example 2: Sentence Conversion

Convert a sentence to lowercase.

TypeScript
    // Original strings
    var str = "TypeScript - String toLowerCase()"; 

    // use of String toLowerCase() Method
    var newstr = str.toLowerCase() 
    console.log(newstr);

Output: 

typescript - string tolowercase()

Why Use toLowerCase()?

  • Case Insensitive Comparisons: When comparing two strings, converting both to lowercase ensures that the comparison is case insensitive.
  • User Input Normalization: Useful in form validations to standardize user inputs before processing.
  • Data Consistency: Ensures consistency in data storage, especially in databases where case sensitivity might lead to duplicates.

Next Article

Similar Reads