JavaScript
JavaScript is the
language of browsers: every Internet browser more-or-less supports it in some way.
The general trend with web developers is to hate JavaScript with no remorse, but I quite like JavaScript and find it a lovely scripting language with wonderful scripting features, just plagued with the syntax of Java: it has first-class functions, closures, prototypes, and curly braces and semicolons everywhere!
Besides the syntax, a few other minor differences in core features (for example, the presence of IO and multithreading), and variable scoping, JavaScript is almost identical to
Lua.
Technically speaking, JavaScript and Java have nothing in common beside the name, which was probably used as a marketing ploy in the wake of the Java Hype of the late 1990s.
Engines
JavaScript is weird; when using the word
JavaScript, one could mean a number of things, including the following:
- ECMAScript
- a dialect of ECMAScript run on most web browsers
- a dialect of ECMAScript run only on Mozilla browsers
ECMAScript
When developers talk about JavaScript, usually they are actually referring to the
ECMAScript Specification, a standard for scripting in web browsers and other programs.
ECMAScript is more-or-less abstract; one does not program in ECMAScript directly like they do with most languages, but in one of its many dialects.
Each of these dialects run on
ECMAScript engines.
"Engine" is a generic programming term for a program that performs some core operations, like an engine in a car provides the power.
Specifically ECMAScript engines are programs that read the code in an ECMAScript context, either interpret it or compile it to bytecode or machine code, then execute it.
Every engine is different, but all implement the ECMAScript Specification and support the primary features.
A Dialect of ECMAScript Run on Most Web Browsers
SpiderMonkey for Mozilla browsers,
Rhino and
Nashorn for Java programs, and
V8 for Chrome and Opera are ECMAScript engines that specifically read the ECMAScript dialect JavaScript.
JavaScript code written for one browser will usually work for other browsers.
A Dialect of ECMAScript Run Only on Mozilla Browsers
Usually in programming, dialects are consistent: JavaScript is not one of those.
SpiderMonkey, Nashorn, and V8 all say they run the JavaScript dialect, yet they all have various differences that set them slightly apart from each other: for example, SpiderMonkey supports rest parameters and sticky RegEx matches, while V8 does not.
Because of this, I wouldn't necessarily say they all are engines for JavaScript but ECMAScript engines that run dialects similar to JavaScript; all except SpiderMonkey.
JavaScript is officially managed and developed by Mozilla, thus Mozilla's engine SpiderMonkey is really the only engine that truly runs JavaScript.