Hi!
I have explained it in the String section. It is because Javascript internally creates an object wrapper for each primitive type (except null and undefined).
For this reason the primitive values are treated as objects when executing methods and properties.
In your example, Javascript internally does this:
I think it's important to say that it 'effectively' does this.
It's unlikely that an implementation will actually do that, and probable that there will be some efficient dispatch table somewhere that does the right thing without going around creating lots of ephemeral String objects. :)
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
If a string is an example of primitive type which doesn't have a prop or method, then why this...??
Hi!
I have explained it in the String section. It is because Javascript internally creates an object wrapper for each primitive type (except null and undefined).
For this reason the primitive values are treated as objects when executing methods and properties.
In your example, Javascript internally does this:
I think it's important to say that it 'effectively' does this.
It's unlikely that an implementation will actually do that, and probable that there will be some efficient dispatch table somewhere that does the right thing without going around creating lots of ephemeral String objects. :)