Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialLuis Zarza
3,145 PointsWhat language is behind JavaScript?
I'm just curious what type of language runs under the hood of the JS language.
What are the foundations of the language written in?
Thank you
3 Answers
Michael Hulet
47,913 PointsA JavaScript interpreter is just a computer program, so just like any other arbitrary computer program, it can be written in any arbitrary Turing-complete language (even JavaScript itself!). Thus, it depends on which specific interpreter you're using, though I believe the most common engines are written in a combination of C and C++
- The original JavaScript interpreter for Netscape Navigator (now known as SpiderMonkey and maintained by Mozilla for FireFox) is in C/C++
- JavaScriptCore, the engine used by WebKit (the web platform used by Safari and all of iOS, watchOS, and tvOS) is in C++
- Blink, the engine used by Chrome, Opera, and recent versions of Edge, is a fork of WebKit, so it's also in C++
- Chakra, the engine used by Internet Explorer and older versions of Edge, is also a combination of C and C++
- V8, the engine used by Node.js and older versions of Chrome, is also written in C++
Luis Zarza
3,145 PointsHi, thanks for you answer. A very complete one indeed!
Although one thing is not clear for me. How can the interpreter be written in JavaScript itself?
I believe to understand this I'd need to know more about interpreters.
Btw, I know for a fact that PHP is written in C. Why is JS different than PHP in that sense?
Michael Hulet
47,913 PointsJavaScript is a Turing-complete language, which means (roughly) that it can express any algorithm or set of mathematical instructions, so you can use it to build any software. A JavaScript interpreter is just software, so you can totally implement a JavaScript interpreter in JavaScript. Given that JavaScript is an interpreted language, however, that would be slow, since you would need to run the interpreter on top of another interpreter. However, it's popular in the field of compiled languages to implement the language's compiler in the language itself, once the compiler is sufficiently advanced. For example the Rust compiler is implemented in Rust itself
A PHP interpreter can also be written in any language you'd like, so it depends on the specific interpreter you're using, just like JavaScript. You're right that the canonical one is implemented in C, but there are several other popular ones. For example, HHVM, the PHP interpreter that Facebook uses, is implemented in C++, OCaml, and Rust
The bottom line here is that the programs that define programming languages (AKA interpreters or compilers) are just computer programs themselves, so they can be implemented in any Turing-complete programming language. The language that your compiler or interpreter was implemented in itself depends on the specific compiler or interpreter you're using. That language is likely ultimately just a personal choice of the person/team who built the compiler/interpreter that you're working with
Luis Zarza
3,145 PointsThank you so much Michael Hulet !
That was an awesome answer.
I think the key to solve my doubt was in here " Given that JavaScript is an interpreted language". I believe then that C is not an interpreted language? and if it is what language is the one who translate C or JavaScript to machine language? That's the missing part for me.
Thank you