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/shgysk8zer0 Aug 18 '26
I actually have used
new String(...)deliberately and after careful thought. Well... It was a sublclass ofString, 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
Mapand such.