JavaScript · Junior · Question 37 of 75
What does this code print?
const s = "hello";
s[0] = "H";
console.log(s);- ✓Correct answer:
hello - 2
Hello - 3
TypeErrorin any mode
Explanation
Strings are immutable: you can't change a character; the assignment is silently ignored (a TypeError in strict mode). You need to create a new string: s[0].toUpperCase() + s.slice(1).