JavaScript (source code)

= JavaScript
{c}

<JavaScript> is a general-purpose <programming language> widely used to implement behavior in web applications. Its core language is standardized by <ECMAScript>; environments such as a <web browser> supply additional facilities, including access to the <Document Object Model>. A language expression and a browser operation consequently need not come from the same specification.<ECMAScript Language Specification by Ecma International>[Overview, Web Scripting and Hosts and Implementations]{ref}

For example, `const squares = [1, 2, 3].map(x => x * x);` produces an array containing `1, 4, 9`. The expression supplies a function that the array's map operation applies to each entry. This computation does not require a page or a document tree. A browser expression such as `document.createElement("p")` instead uses the host's document interface.<ECMAScript Language Specification by Ecma International>[Array.prototype.map and arrow-function expressions]{ref}<DOM Standard by WHATWG>[Document.createElement]{ref}

Values and conversion rules matter. `1 + 2` evaluates to the number three, while `"1" + 2` evaluates to the text `"12"` because that addition operation performs string concatenation. Reading the exact operand types explains the result more reliably than treating every plus sign as numerical addition.<ECMAScript Language Specification by Ecma International>[Addition Operator, evaluation and string concatenation]{ref}

<Lexical scope> determines which binding an expression refers to from the surrounding program structure. In an interactive page, the language can use those bindings while reading or changing <DOM nodes>. Distinguishing the core language, its environment and the program's own data makes examples easier to transfer between browser and nonbrowser implementations.