I am testing immutability of a string and wrote this function that takes in a String.
Since a string is immutable, str[i] below, cannot be assigned to any value.
However, when I run this function, it does not give me an error. Why is that? (as per my study, I believe this line (str[i] ='x' should break the system/stop executing the function and throw an error. But it does not (this is written in VSCode editor)
function tuc(str) {
let res = [];
for (let i = 0; i < str.length; i++) {
str[i]='x';
let c = str[i];
res.push(c.toUpperCase());
}
return res.join("");
}