Home > Back-end >  How can primitive data types have access to prototype?
How can primitive data types have access to prototype?

Time:02-13

How primitive data types (strings, numbers etc.) have access to methods like .toString(). We can even access to their proto's by typing variable.proto but they are not object.

CodePudding user response:

JavaScript automatically converts primitives to String objects, so that it's possible to use String object methods for primitive strings.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

  • Related