0
0
Typescriptprogramming~20 mins

String type behavior in Typescript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
String Type Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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);
A"Hello World"
B"HelloWorld"
C"Hello+World"
D"Hello World!"
Attempts:
2 left
💡 Hint
Think about how the + operator works with strings.
Predict Output
intermediate
2: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}`);
A"Name: Alice, Age: 30"
B"Name: ${name}, Age: ${age}"
C"Name: Alice, Age: "
D"Name: Alice Age: 30"
Attempts:
2 left
💡 Hint
Look at how template literals insert variables.
Predict Output
advanced
2: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]);
A"r"
B"S"
Cundefined
D"c"
Attempts:
2 left
💡 Hint
Remember that string indexing starts at 0.
Predict Output
advanced
2: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;
ANo error, greeting becomes '123'.
BType 'number' is not assignable to type 'string'.
CRuntime error: Cannot assign number to string.
DSyntaxError: Invalid assignment.
Attempts:
2 left
💡 Hint
TypeScript checks types at compile time.
🧠 Conceptual
expert
2: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?
A7
B1
C11
D4
Attempts:
2 left
💡 Hint
Think about how JavaScript counts characters in strings with emoji and zero-width joiners.