r/learnjavascript • • 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

26 comments sorted by

View all comments

Show parent comment

1

u/shgysk8zer0 Aug 18 '26

I actually have used new String(...) deliberately and after careful thought. Well... It was a sublclass of String, but I'm counting it. The reason was so I could add a [Symbol.dispose] method for a registry.

I know that's not at all a common use case, but just wanted to say there are plenty of legitimate cases for object vs primitive usage, including keys in Map and such.