Where are the properties/methods like parseInt and parseFloat defined?

58 Views Asked by At
console.log(Object.prototype.hasOwnProperty('parseInt'));  // false
console.log(Number.prototype.hasOwnProperty('parseInt'));  // false

Where is parseInt defined if not on the default prototype object (Object.prototype), the prototype object from which all JS objects inherit?

1

There are 1 best solutions below

0
Aryn Thernium On

Both parseInt and parseFloat are native code, so they will depend on the implementation. Neither function has a prototype.

Somewhere in this commit, there are some definitions for GlobalParseInt and GlobalParseFloat. If you have knowledge of C/natives, you could take a look and learn for yourself. As for Spidermonkey, Firefox's engine, I couldn't find an exact file but did find many references to the parseInt function in this search.