97

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?

3
  • 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) :) Commented Aug 10, 2011 at 4:22
  • I am guessing there are a number of different JavaScript engines written in all sorts of different languages. Commented 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/… Commented Nov 12, 2019 at 12:45

7 Answers 7

145

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Indeed. Although I'd wager that the majority of them are implemented in C++ (or C and its derivatives). Rhino is obviously Java.
Is Python a standard also? Is every language except C and C++ a standard? I can't find any information. on the differences.
So is JavaScript just an intricate conceptual idea? E.g. in the same way I could write down the the specifications for a House (it must have 1 door, 2 rooms, 2 windows per room, running water, electricity etc), then other people could interpret those specifications, build a house and call it a House? I am assuming the answer is no, because there was a creator of the language and surely he actually made a functioning 'thing'. What was that initial thing? What did it look like? And what language was it written in (or was it 'just' an abstraction/shorthand for machine code)?
PS - maybe the first ‘thing’ created was the first JavaScript engine, SpiderMonkey, which was written in C: en.m.wikipedia.org/wiki/SpiderMonkey , see also: brendaneich.com/2011/06/new-javascript-engine-module-owner
|
42

All the answers so far are correct, but since it hasn't been mentioned yet, JavaScript can be written in JavaScript.

3 Comments

Atwood's Law at its' finest!
Cool reply, but the geek in me has to correct you too. SpiderMonkey is an engine, so there is the chick, but I don't see the egg,
I used the stones to destroy the stones
12

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

8

Whichever language the client webbrowsers javascript interpreter was written in :)

Comments

8

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

There could be multiple implementations of PHP, but... no one's interested.
@IgnacioVazquez-Abrams - turns out Facebook were interested :)
0

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

No. The semantics of JavaScript execution do not depend on the language used to implement them.
You can write functions under the hood to bypass that behavior (i.e. new and garbage collect in c++ instead of setting pointer). The fact that Javascript (technically EMCA) behaves the way it does has little if anything to do with its implementation language because it's just a standard
-5

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

This is wrong. Java is a not a subset of C++. C++ is not considered a low level language. You might be thinking of C, and even then Java and other languages are not a 'subset' of C. They might be based on C, but they are not a subset. The accepted answer gives a better answer, which is that Javascript can be writeen in any language, but that the most popular implementation is in C++ ie Google's V8.
I do not understand what you mean by that. C++ is another language that originated as a superset of C. If any language is a subset of C++, then this python code should work in C++: 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++

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.