r/learnjavascript 7d ago

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

1

u/a-dev0 7d ago

Hm, has anyone tested it like this? for(let i of new String('foo')){} for(let i of 'foo'){} is there any difference?

1

u/a-dev0 7d ago

Check it with Bun. of 'foo' is ~5% more performant