DEV Community

Discussion on: Everything You Should Know About Javascript Variables

Collapse
 
codenutt profile image
Jared

So, I looked into this because I was curious. The types themselves are in fact primitives and immutable, however, as noted in MDN:

That's why Primitives are immutable - instead of working on them directly, we're working on a copy, without affecting the original.

When we say let string = "some string", the "some string" portion is a primitive, however, that variable is wrapped in a String class, which does have methods.

Reference: developer.mozilla.org/en-US/docs/G...

Thank you for pointing that out and making me dig deeper!