If it's a scripting language as the name implies it must be written in a lower level language right? Like how PHP is written in C what language is JavaScript written in?
-
9"it must be written in a lower language", not necessarily, for example, Narcissus is a Javascript interpreter, written in pure Javascript (it's a meta-circular evaluator) :)Christian C. Salvadó– Christian C. Salvadó2011-08-10 04:22:14 +00:00Commented Aug 10, 2011 at 4:22
-
I am guessing there are a number of different JavaScript engines written in all sorts of different languages.Galik– Galik2014-11-29 03:17:21 +00:00Commented Nov 29, 2014 at 3:17
-
1@CMS Yes, but the underlying question here is, what language first JS interpreter is written? You cannot write JavaScript Interpreter in JavaScript, when you have no tool to read you JavaScript code (Which is Interpreter in this case). This link here explains this chicken egg problem: stackoverflow.com/questions/18247888/…RegarBoy– RegarBoy2019-11-12 12:45:38 +00:00Commented Nov 12, 2019 at 12:45
7 Answers
Javascript is just a standard, more formally known as ECMAScript. It can be implemented in any language, just like any standard.
Chrome's Javascript engine, V8, is written in C++.
From the project page:
V8 is written in C++ and is used in Google Chrome, the open source browser from Google.
V8 implements ECMAScript as specified in ECMA-262, 5th edition, and runs on Windows (XP or newer), Mac OS X (10.5 or newer), and Linux systems that use IA-32, x64, or ARM processors.
Firefox's Javascript engine, SpiderMonkey (and now TraceMonkey) is also written in C++. And as maerics below said, Rhino is written in Java.
6 Comments
All the answers so far are correct, but since it hasn't been mentioned yet, JavaScript can be written in JavaScript.
3 Comments
Most Javascript interpreters are written in C/C++ (V8, Nitro, etc…), however a compliant interpreter can be written in any language (Rhino→Java, Interpreter→Javascript, etc…).
Comments
Javascript is an implementation of the ECMAScript standard, but there is no singular canonical interpreter like you see with PHP.
Most of the major implementations (standalone or as parts of web browsers) out there tend to be largely written in C or C++ for performance reasons, but that's not necessarily always the case. Rhino, an engine maintained by Mozilla, is written in Java.
2 Comments
Most implementations of Javascript show behaviour that is clearly caused by the use of pointers and byref parameter passing, which normally points towards the use of C, or C++
This is clearly notable for instance when you are taking apart a multidimensional array in a loop, with the help of intermediate array's. These tend to behave very "strangely", if you are not familiar with pointers and byref passing of parameters (You need do var hlp = new Array() each time or it will overwrite the previous values which you already stored somewhere else)
I'm rather curious as to how an implementation of javascript in for instance Java, because I imagine that this kind of behaviour will be quite different in that case?
2 Comments
C++ is the fundamental language for anything modern and fancy. Most modern high level languages are subset of low level language,C++. All modern languages you see today is a subset of C++ someway or the other. Even Java is a subset of C++.
2 Comments
print("hello world"). Paste it into a new file and compile it with a C++ compiler. Does it compile? If it doesn't, then Python is not a subset of c++