Recall & Review
beginner
What does the
toUpperCase() method do in TypeScript strings?It converts all the letters in a string to uppercase letters. For example, "hello" becomes "HELLO".
Click to reveal answer
beginner
What is the purpose of the
toLowerCase() method in TypeScript?It changes all the letters in a string to lowercase letters. For example, "WORLD" becomes "world".
Click to reveal answer
beginner
How would you convert the string "TypeScript" to uppercase in TypeScript?
Use the code:
"TypeScript".toUpperCase(). This returns "TYPESCRIPT".Click to reveal answer
beginner
How do you convert a string to lowercase in TypeScript?
Call the
toLowerCase() method on the string. For example, "HELLO".toLowerCase() returns "hello".Click to reveal answer
intermediate
Are
toUpperCase() and toLowerCase() methods destructive (do they change the original string)?No, strings in TypeScript are immutable. These methods return a new string with the changes, leaving the original string unchanged.
Click to reveal answer
What will
"hello world".toUpperCase() return?✗ Incorrect
The
toUpperCase() method converts all letters to uppercase.Which method converts a string to all lowercase letters?
✗ Incorrect
toLowerCase() is the correct method to convert strings to lowercase.If you run
let s = "Test"; s.toUpperCase(); console.log(s);, what is printed?✗ Incorrect
Strings are immutable, so
s.toUpperCase() returns a new string but does not change s.What type of value do
toUpperCase() and toLowerCase() return?✗ Incorrect
Both methods return a new string with the case changed.
Which of these is NOT true about
toUpperCase() and toLowerCase()?✗ Incorrect
Strings are immutable, so these methods do not change the original string.
Explain how to convert a string to uppercase and lowercase in TypeScript. Include what happens to the original string.
Think about string immutability and method names.
You got /4 concepts.
Describe a real-life example where converting text to uppercase or lowercase might be useful in a program.
Consider how computers treat letters differently by case.
You got /4 concepts.