What does it mean for Javascript to be open source?

What does it mean for javascript to be open source?

Can I look up in the code for javascript how a for loop is implemented?

Can I look in code for javascript to find the definition of array.find(); and other functions like it?

How would I find the code in the Javascript language for a for loop and array.find(), if it’s possible?

I know where documentation is. I am not talking about documentation. I’m talking about the code for javascript. I want to “pop the hood” so to speak, and see how the language works/ is written.

It’s not quite what you’d call open source. JavaScript is what a given implementation of ECMAScript is called. ECMAScript is a standard. The document I’ve linked specifies how the language should work (doesn’t care about things like files or networking or anything, just the core language).

It doesn’t specify how to implement it, and so there are lots of JavaScript engines: the actual code that you’re talking would be unique to each one of them. Here’s one list of engines. Most of those are open source, but some aren’t. The mostly widely used is called v8, it’s what powers Chrome and Node and Deno and various other things. Here is the source code viewer for Google’s version of the Chromium browser, drilled down to v8 - note that there’s an entire application just for viewing/searching the source code.

So the answer to “where do I look at the code that actually runs {a given function}” is going to be “it depends on which engine you’re using”. The answer to “how does {a given function} need to work in an abstract way” is in the ECMAScript spec.

Note that there’s an author called Axel Rauschmayer who writes very detailed explanations of JavaScript, they’re often more approachable than the ECMA specification for understanding how things work: Speaking Javascript and Exploring ES6 are the two books you probably want bookmarking

There is an engine written entirely in JS which is used for testing new features which is fully spec-compliant, so that’s possibly the most approachable, but caveat that any engine is going to be incredibly complicated. Plus there’s no reason to write the engine in JS, normally they use C++ or similar.

Some languages have very approachable codebases: you can go look at the code and see straightaway how a give bit of functionality works. JS is not like that, what you’re asking is slightly more complicated than it might seem. There is a standard specification, and the language has to conform to that, but how it is actually programmed, how it actually conforms, that’s completely up to the team building a given engine.

Note that what you’re asking is basically “how does an interpreter/compiler work”. If you really really really want to know this, then I’d suggest these two books: Writing an Interpreter in Go/Writing a Compiler in Go, which go through writing a JavaScript-like language called Monkey in a very approachable way.

1 Like

This is awesome information and the BOOKS by Dr. Axel Rauschmayer are FREE!! Thank you for your response, its been very helpful

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.