r/learnjavascript • • Jul 09 '23

Is string/number also an object in JavaScript?

https://www.youtube.com/watch?v=9W0-vljG2-I

[removed] — view removed post

1 Upvotes

3 comments sorted by

0

u/[deleted] Jul 09 '23

[deleted]

-1

u/xplodivity Jul 09 '23

The mdn docs say otherwise. String primitives are converted to string objects automatically behind the scenes everytime we try to access a method on a normal string primitive.

Here’s what mdn says in their exact words:

String literals (denoted by double or single quotes) and strings returned from String calls in a non-constructor context (that is, called without using the new keyword) are primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup on the wrapper object instead.

0

u/[deleted] Jul 09 '23

[deleted]

1

u/MoTTs_ Jul 09 '23

This is interesting! Could you link to the relevant parts of the source? It's a big codebase.