What is the best way, if even possible, to see the underlying code for the predefined functions in Javascript. Is there documentation that shows how these were coded, or an easy way to actually view the underlying code?
parseInt
parseFloat
isNaN
What is the best way, if even possible, to see the underlying code for the predefined functions in Javascript. Is there documentation that shows how these were coded, or an easy way to actually view the underlying code?
parseInt
parseFloat
isNaN
After looking further I found this in the ECMAScript specification. http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
When the parseInt function is called, the following steps are taken:
When the parseFloat function is called, the following steps are taken:
NOTE parseFloat may interpret only a leading portion of string as a Number value; it ignores any characters that cannot be interpreted as part of the notation of an decimal literal, and no indication is given that any such characters were ignored.
Returns true if the argument coerces to NaN, and otherwise returns false.
They are native functions, and maybe coded in the language your JS engine was written in - you'd need to contact it's source.
However, you probably are more interested in the EcmaScript specification that describes how the algorithms work.
And if you're lucky, for some of the functions you even might find an JS equivalent. You'll find them mostly on pages that test ES implementations against the standard.
console.log(parseInt) //=> function parseInt() { [native code] }
–
Laurenlaurena After looking further I found this in the ECMAScript specification. http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf
When the parseInt function is called, the following steps are taken:
When the parseFloat function is called, the following steps are taken:
NOTE parseFloat may interpret only a leading portion of string as a Number value; it ignores any characters that cannot be interpreted as part of the notation of an decimal literal, and no indication is given that any such characters were ignored.
Returns true if the argument coerces to NaN, and otherwise returns false.
Those functions are implementation specific depending on browser, and are not written in JS (unless somebody's decided to write a browser engine in JS). The code is not guaranteed to be the same across environments, though they do have to (in theory) adhere to the ECMAScript specification for their behavior.
© 2022 - 2024 — McMap. All rights reserved.