Challenge - 5 Problems
String Type Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this string concatenation?
Consider the following TypeScript code snippet. What will be printed to the console?
Typescript
const a: string = 'Hello'; const b: string = 'World'; console.log(a + ' ' + b);
Attempts:
2 left
💡 Hint
Think about how the + operator works with strings.
✗ Incorrect
The + operator concatenates strings. Adding a space between the two strings results in "Hello World".
❓ Predict Output
intermediate2:00remaining
What is the output of this template literal?
What will this TypeScript code print to the console?
Typescript
const name: string = 'Alice'; const age: number = 30; console.log(`Name: ${name}, Age: ${age}`);
Attempts:
2 left
💡 Hint
Look at how template literals insert variables.
✗ Incorrect
Template literals replace ${variable} with the variable's value inside the string.
❓ Predict Output
advanced2:00remaining
What is the output of this string indexing?
What will this TypeScript code print to the console?
Typescript
const str: string = 'TypeScript'; console.log(str[4]);
Attempts:
2 left
💡 Hint
Remember that string indexing starts at 0.
✗ Incorrect
Index 4 in 'TypeScript' is the fifth character, which is 'c'.
❓ Predict Output
advanced2:00remaining
What error does this code raise?
What happens when you try to assign a number to a string variable in TypeScript?
Typescript
let greeting: string = 'Hi'; greeting = 123;
Attempts:
2 left
💡 Hint
TypeScript checks types at compile time.
✗ Incorrect
TypeScript does not allow assigning a number to a variable declared as string, causing a compile-time error.
🧠 Conceptual
expert2:00remaining
How many characters are in this string?
Consider the string with Unicode characters: const s = '👩👩👧👦'; How many characters does s.length report in TypeScript?
Attempts:
2 left
💡 Hint
Think about how JavaScript counts characters in strings with emoji and zero-width joiners.
✗ Incorrect
The string contains multiple Unicode code units including zero-width joiners, so length counts code units, not user-perceived characters.