E.g., alert(), Object(), String(), etc. How would I see the code behind these functions?
Would I need to understand the language that an engine, such as V8, is written in and read through that, or is there a simpler solution?
Go to the outer edge of a site (e.g. far left), then right-click and click on “View Page Source” (or the option that's similarly named). That will bring up all the HTML code, along with links to CSS files, Javascript, images, etc.
#JavaScript Functions are Objects! They are not objects, don't have methods and they are stored in memory by value. Non-Primitives (functions, arrays and objects): these are mutable data types. They are objects and they are stored in memory by reference.
Global variables live until the page is discarded, like when you navigate to another page or close the window. Local variables have short lives. They are created when the function is invoked, and deleted when the function is finished.
Use the typeof operator to check if a function is defined, e.g. typeof myFunction === 'function' . The typeof operator returns a string that indicates the type of a value. If the function is not defined, the typeof operator returns "undefined" and doesn't throw an error.
How would I see the code behind these functions?
You would need to find the source code for the relevant project (Firefox, Chromium, V8, SpiderMonkey, etc.), provided the project is open-source.
Would I need to understand the language that an engine such as V8 is written in and read through that, or is there a simpler solution.
Yes, you would. Note that alert
is not a JavaScript function, it's a function defined by web browsers (so you'd need to look at the Firefox or Chromium, etc., source). Object
and String
are both part of JavaScript, so you'd look at the JavaScript engine sources for those (SpiderMonkey [or whateverMonkey, the prefix seems to change a lot] and V8, etc.).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With