Looking to get a head start on your next software interview? Pickup a copy of the best book to prepare: Cracking The Coding Interview!
let myString = "HELLO WORLD";
let lowerCaseString = myString.toLowerCase();
console.log(lowerCaseString); // Output: "hello world"
In the example above, we first declare a string variable called myString and assign it the value “HELLO WORLD”. We then call the toLowerCase() method on myString and assign the result to a new variable called lowerCaseString. Finally, we log the value of lowerCaseString to the console, which outputs “hello world”.
It is important to note that the toLowerCase() method does not modify the original string. Instead, it returns a new string with all the characters converted to lowercase. Therefore, if you want to modify the original string, you need to assign the result of the toLowerCase() method back to the original variable.
In conclusion, the toLowerCase() method is a useful tool for manipulating strings in TypeScript. By using this method, you can easily convert a string to lowercase and perform other string operations.