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?
A"HELLO world"
B"hello world"
C"Hello World"
D"HELLO WORLD"
✗ Incorrect
The toUpperCase() method converts all letters to uppercase.
Which method converts a string to all lowercase letters?
AtoLower()
BtoUpperCase()
CtoLowerCase()
DlowerCase()
✗ 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?
A"Test"
B"TEST"
C"test"
DError
✗ 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?
AAn array
BA new string
CA number
DUndefined
✗ Incorrect
Both methods return a new string with the case changed.
Which of these is NOT true about toUpperCase() and toLowerCase()?
AThey change the original string.
BThey return a new string.
CThey work on string values.
DThey do not modify the original string.
✗ 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.
Practice
(1/5)
1. Which TypeScript string method converts all characters in a string to uppercase?
easy
A. convertCase()
B. toLowerCase()
C. toTitleCase()
D. toUpperCase()
Solution
Step 1: Understand string case methods
TypeScript strings have built-in methods to change letter cases, including toUpperCase() and toLowerCase().
Step 2: Identify method for uppercase
The method toUpperCase() changes all letters to uppercase, while toLowerCase() changes to lowercase.
Final Answer:
toUpperCase() -> Option D
Quick Check:
Uppercase method = toUpperCase() [OK]
Hint: Uppercase method always has 'Upper' in its name [OK]
Common Mistakes:
Confusing toUpperCase() with toLowerCase()
Thinking toTitleCase() exists in TypeScript
Assuming convertCase() is a valid method
2. Which of the following is the correct syntax to convert a string variable name to lowercase in TypeScript?
easy
A. name.toLowerCase()
B. toLowerCase(name)
C. name.lowercase()
D. lowerCase(name)
Solution
Step 1: Recall method call syntax on strings
In TypeScript, string methods are called on the string variable using dot notation.
Step 2: Identify correct method name and usage
The method to convert to lowercase is toLowerCase(), called as name.toLowerCase(). Other options are invalid syntax or incorrect method names.
Final Answer:
name.toLowerCase() -> Option A
Quick Check:
Lowercase method called on variable = name.toLowerCase() [OK]
Hint: String methods use dot notation like variable.method() [OK]
Common Mistakes:
Using function style like toLowerCase(name)
Using incorrect method names like lowercase()
Missing parentheses after method name
3. What will be the output of the following TypeScript code?
const text = "Hello World";
console.log(text.toUpperCase());
medium
A. "hello world"
B. SyntaxError
C. "HELLO WORLD"
D. "Hello World"
Solution
Step 1: Understand the input string and method
The string is "Hello World" and the method toUpperCase() converts all letters to uppercase.
Step 2: Apply toUpperCase() to the string
Applying toUpperCase() changes "Hello World" to "HELLO WORLD".
Final Answer:
"HELLO WORLD" -> Option C
Quick Check:
toUpperCase() output = "HELLO WORLD" [OK]
Hint: toUpperCase() makes all letters big exactly [OK]
Common Mistakes:
Expecting lowercase output instead
Thinking original string is unchanged in output
Confusing method name causing syntax error
4. Identify the error in this TypeScript code snippet:
let greeting = "Hi There";
console.log(greeting.toLowercase());
medium
A. Missing semicolon after string declaration
B. toLowercase() is not a valid method; correct is toLowerCase()
C. Variable greeting should be const, not let
D. Console.log should be console.Log
Solution
Step 1: Check method name spelling
The method to convert string to lowercase is toLowerCase() with capital 'C'. The code uses toLowercase() with lowercase 'c', which is invalid.
Step 2: Verify other syntax elements
Semicolon is optional in TypeScript, let is valid for variable, and console.log is case-sensitive and correct as written.
Final Answer:
toLowercase() is not a valid method; correct is toLowerCase() -> Option B
Quick Check:
Method name case matters: toLowerCase() correct [OK]
Hint: Method names are case-sensitive; watch capital letters [OK]
Common Mistakes:
Ignoring case sensitivity in method names
Thinking semicolon is mandatory error
Confusing console.log capitalization
5. You have an array of strings: const fruits = ["Apple", "BANANA", "Cherry"]; How do you create a new array where all fruit names are lowercase using TypeScript?
hard
A. fruits.map(fruit => fruit.toLowerCase())
B. fruits.toLowerCase()
C. fruits.forEach(fruit => fruit.toLowerCase())
D. fruits.map(fruit => toLowerCase(fruit))
Solution
Step 1: Understand array transformation
To change each string in an array, use map() to create a new array with transformed values.
Step 2: Apply toLowerCase() inside map callback
Inside map, call fruit.toLowerCase() to convert each string to lowercase. This returns a new array with all lowercase fruits.
Final Answer:
fruits.map(fruit => fruit.toLowerCase()) -> Option A
Quick Check:
Use map() with toLowerCase() for array lowercase [OK]
Hint: Use map() with toLowerCase() to transform arrays [OK]
Common Mistakes:
Calling toLowerCase() directly on array
Using forEach which returns void, not new array
Trying to call toLowerCase() as a standalone function
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.