Can somebody explain this behaviour
Code:
name = "ABC"
console.log(name)
name[0] = "B"
console.log(name)
Output Expected:
ABC
BBC
Strings are immutable/readonly due to the fact that they are primitive data types in JavaScript. You can only generate new strings.
name = "ABC"
console.log(name)
name = "B" + name.slice(1);
console.log(name)
To read more about primitives-MDN-Primitives
"use strict;"as the first statement), it will throw an error, for example (in Chrome)TypeError: Cannot assign to read only property '0' of string 'ABC'