Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

Can you change a character in a JavaScript string?

Do you know what will be the output of this code?

JavaScript
const str = "hello";
str[0] = "H";
console.log(str);
Show answer and explanation

The answer is "hello".

Strings can’t be changed in place. The assignment is silently ignored (in strict mode it throws). Build a new string: "H" + str.slice(1).

Take the full quiz Next question →

More Strings questions

  1. Why does ('b' + 'a' + + 'a' + 'a') return "banana"?
  2. Why is "a string" instanceof String false?
  3. Why does 1 + "2" + "2" return "122"?
  4. What does String.raw do in JavaScript?
  5. Why is "10" < "9" true in JavaScript?

Related topics