DEV Community

Discussion on: LEVEL UP with JavaScript! LVL 6

jonrandy profile image
Jon Randy • Edited on

Huh? Not sure what you're talking about here - strings are not immutable in JS. Your console.log(name) will show Wizard in the console. The return value of console.log is undefined, but that is always the case with console.log - whatever you pass to it

lukeshiru profile image

Yes and no. Strings are immutable:

const example = "foo";
example[0] = "x"; // This does nothing
example === "foo"; // So this is true
Enter fullscreen mode Exit fullscreen mode

But as you mentioned, the example @devcronin gave with undefined, doesn't make any sense. console.log always returns undefined, so that has nothing to do with mutation. Also the example is not actually "mutating" name, is just assigning a new value to it.

devcronin profile image
DevCronin Author

I am a Jr dev and believe this was just a mistake on my part. I do my best to ensure I keep my content accurate. Thank you both for replying and pointing out my error.