JavaScript · Junior · Question 37 of 75

What does this code print?

const s = "hello";
s[0] = "H";
console.log(s);

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

Further reading

Problem with a question

JavaScript · Junior · question 37

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