DEV Community

Discussion on: Is everything in JavaScript an Object?

Collapse
 
peerreynders profile image
peerreynders

If you assign some property to a string primitive with an intention of getting the value back at some point, you will only be returned undefined because the temporary String Object was discarded then and there.

MDN: primitive values:

All types except objects define immutable values (that is, values which can't be changed).

seems like a more straightforward explanation - i.e. nothing was changed in the first place - JavaScript just ignores the attempt of mutation.

Collapse
 
mayankav profile image
mayankav • Edited

@peerreynders Indeed. Thanks for taking out time to read :)