JavaScript · Junior · Question 57 of 75
What does this code print in a classic (non-strict) script?
let s = "cat";
s[0] = "b";
console.log(s);- ✓Correct answer:
cat - 2
bat - 3It throws a
TypeError
Explanation
Strings are immutable: index assignment is silently ignored (or throws in strict mode). Create a new string instead: "b" + s.slice(1).