Challenge - 5 Problems
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediateWhat is the output of this string concatenation code?
Consider the following JavaScript code that concatenates strings. What will be printed?
DSA Javascript
let a = 'Hello'; let b = 'World'; let c = a + ' ' + b; console.log(c);
Attempts:
2 left
💡 Hint
Look at how spaces are added between strings in concatenation.
✗ Incorrect
The code concatenates 'Hello', a space ' ', and 'World'. So the output is 'Hello World'.
❓ Predict Output
intermediateWhat is the output of this string indexing code?
What will this code print when accessing characters by index?
DSA Javascript
const str = 'Data'; console.log(str[0]); console.log(str[3]);
Attempts:
2 left
💡 Hint
Remember string indexing starts at 0.
✗ Incorrect
str[0] is 'D' (first letter), str[3] is 'a' (fourth letter).
🧠 Conceptual
advancedHow are strings stored in memory in JavaScript?
Which statement best describes how JavaScript stores strings in memory?
Attempts:
2 left
💡 Hint
Think about immutability and encoding in JavaScript strings.
✗ Incorrect
JavaScript strings are immutable and stored as sequences of UTF-16 code units in contiguous memory.
❓ Predict Output
advancedWhat is the output of this code using string methods?
What will this code print?
DSA Javascript
const s = 'Memory'; const result = s.slice(1, 4); console.log(result);
Attempts:
2 left
💡 Hint
slice(start, end) extracts characters from start up to but not including end.
✗ Incorrect
slice(1,4) extracts characters at indices 1,2,3 which are 'e','m','o'.
❓ Predict Output
expertWhat is the output of this code showing string immutability?
What will this code print?
DSA Javascript
let str = 'Hello'; str[0] = 'Y'; console.log(str);
Attempts:
2 left
💡 Hint
Strings cannot be changed by assigning to an index.
✗ Incorrect
Strings are immutable, so str[0] = 'Y' does nothing. str remains 'Hello'.
