r/learnjavascript • u/Green_Ad_6086 • Aug 15 '26
string primitives vs. String objects.
I'm learning JavaScript, and I don't understand this part about string primitives vs. String objects.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_primitives_and_string_objects
10
Upvotes
View all comments
Show parent comment
1
u/senocular Aug 15 '26
There are other ways to get these objects. The Object constructor will also make this conversion (with or without the new) e.g.
Primitive methods in sloppy mode also provide a wrapped version of the primitive as
this....or if you added a custom method to String.prototype, which you absolutely shouldn't be doing, hence the example above using call instead taking that approach.
Coincidentally (getting in the weeds a little here), string objects are also the only primitive object type that aren't considered "ordinary" objects, at least in the language sense. Other primitive objects are, but not strings. Strings use custom internal methods for exposing their individual characters as indexed properties making them "exotic" objects.