Looking to get a head start on your next software interview? Pickup a copy of the best book to prepare: Cracking The Coding Interview!
To convert a string to uppercase in TypeScript, we can use the `toUpperCase()` method. This method returns a new string with all the characters in uppercase.
Here is an example code snippet:
const str = "hello world";
const upperCaseStr = str.toUpperCase();
console.log(upperCaseStr); // "HELLO WORLD"
In the above code, we first declare a string variable `str` with the value “hello world”. We then call the `toUpperCase()` method on the `str` variable and assign the result to a new variable `upperCaseStr`. Finally, we log the value of `upperCaseStr` to the console, which outputs “HELLO WORLD”.
It is important to note that the `toUpperCase()` method does not modify the original string. Instead, it returns a new string with all the characters in uppercase.
In conclusion, converting a string to uppercase in TypeScript is a simple task that can be accomplished using the `toUpperCase()` method.