= JavaScript engine
{c}
A <JavaScript engine> implements the execution of <JavaScript> programs according to the applicable <ECMAScript> language rules. It reads program structure and performs the operations that produce values, state changes and errors. The engine is one component of an environment; a <web browser> additionally supplies document, networking and interaction facilities.<ECMAScript Language Specification by Ecma International>[§§1–2, Scope and Conformance; §4.2, Hosts and Implementations]{ref}
For example, `function square(n) { return n * n; } square(7);` evaluates to `49`. An <interpreter> can execute a representation of these operations, while compilation can translate operations into another executable form. <Just-in-time compilation> performs compilation during execution rather than requiring a wholly separate advance compilation step. These implementation choices do not change the multiplication result required by the language.
A concrete implementation is <V8>, whose <Ignition (JavaScript interpreter)> is documented as a register-based <interpreter>. Such an implementation can use intermediate <bytecode> rather than repeatedly treating source text as its direct execution format. This example describes one engine architecture, not a requirement that every <JavaScript engine> use the same machinery.<Ignition in the V8 documentation>[Opening description and linked interpreter overview]{ref}
Host facilities must be distinguished from language execution. Evaluating a call involving `document` requires the environment to supply that object; implementing <ECMAScript> alone does not promise the <Document Object Model>. Conversely, numerical computations need not create any document nodes.
Performance comparisons require a specified workload. Parsing, first execution, repeated execution and calls into host facilities can have different costs. Timing only a tiny warmed-up function therefore does not measure every aspect of loading or running an application, even when the returned values are identical.
Back to article page