Challenge - 5 Problems
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateOutput of String Concatenation and Length
What is the output of the following TypeScript code?
DSA Typescript
const s1 = "hello"; const s2 = "world"; const s3 = s1 + " " + s2; console.log(s3.length);
Attempts:
2 left
💡 Hint
Count all characters including the space between words.
✗ Incorrect
The string s3 is "hello world" which has 11 characters including the space.
❓ Predict Output
intermediateString Immutability Effect
What will be printed after running this TypeScript code?
DSA Typescript
let str = "abc"; str[0] = "z"; console.log(str);
Attempts:
2 left
💡 Hint
Strings cannot be changed by index assignment in TypeScript.
✗ Incorrect
Strings are immutable in TypeScript. Assigning to str[0] does nothing, so str remains "abc".
❓ Predict Output
advancedMemory Representation of String Characters
What is the output of this TypeScript code that prints character codes?
DSA Typescript
const s = "Hi!"; const codes = []; for (let i = 0; i < s.length; i++) { codes.push(s.charCodeAt(i)); } console.log(codes);
Attempts:
2 left
💡 Hint
Use ASCII codes: 'H' = 72, 'i' = 105, '!' = 33.
✗ Incorrect
charCodeAt returns the UTF-16 code unit for each character. 'H' is 72, 'i' is 105, '!' is 33.
🧠 Conceptual
advancedUnderstanding String Interning
Which statement about string interning in TypeScript/JavaScript is true?
Attempts:
2 left
💡 Hint
Think about immutability and memory sharing behavior in JavaScript strings.
✗ Incorrect
Strings are immutable, but JavaScript engines may or may not share memory for identical strings. This is an implementation detail and not guaranteed.
🔧 Debug
expertWhy does this string slicing code produce unexpected output?
Consider this TypeScript code snippet. What is the output and why?
DSA Typescript
const s = "abcdef"; const slice1 = s.slice(2, 4); const slice2 = s.slice(4, 2); console.log(slice1); console.log(slice2);
Attempts:
2 left
💡 Hint
Check how slice behaves when the start index is greater than the end index.
✗ Incorrect
slice(start, end) returns substring from start up to but not including end. If start > end, it returns empty string.
