Mutability And Reference VS Privative Types in JavaScript
Last updated
Last updated
Mutability && Primitive && Reference Examples
In JavaScript, String
values are immutable, which means that they cannot be altered once created.
For example, the following code:
cannot change the value of myStr
to Job
, because the contents of myStr
cannot be altered. Note that this does not mean that myStr
cannot be changed, just that the individual characters of a string literal cannot be changed. The only way to change myStr
would be to assign it with a new string, like this:
Strings are passed by value, are immutable, and a new array is constructed and returned, because it cannot be changed in place.
To dereference an array, use let [var1, var2]
syntax.
To dereference attributes from an object, use let {}
syntax.
Web-Dev-Hub Bryan best-celery-b2d7c.netlify.app
By Bryan Guner on May 27, 2021.
Exported from Medium on August 31, 2021.