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);

Explanation

Strings are immutable: index assignment is silently ignored (or throws in strict mode). Create a new string instead: "b" + s.slice(1).

Further reading

Problem with a question

JavaScript · Junior · question 57

Test yourself

Take the JavaScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz