DEV Community

Discussion on: Everything You Should Know About Javascript Variables

Collapse
 
devdufutur profile image
Rudy Nappée


In JavaScript, a primitive (primitive value, primitive data type) is data that is not an object and has no methods.

Actually numbers and strings do have methods 😉

Collapse
 
codenutt profile image
Jared

That is a good point!

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!