JavaScript: Difference between revisions

Content deleted Content added
undo listing of online products using JS. It is not relevant which companies use it. The relevant bit is it being "core tech" of the web and "majority sites" using it. To support that claim, we need an external source corroborating these facts, possibly by the external source (optionally) providing examples of products. Mentioning it in the article is both out of scope, and also not a valid way to verify the claim. See also Wikipedia:No_original_research and Wikipedia:Verifiability
link to web platform in lead
 
(1,000 intermediate revisions by more than 100 users not shown)
Line 1:
{{Short description|High-level programming language}}
{{pp-pc1|small=yes}}
{{distinguishDistinguish|Java (programming language)|Java (software platform)|Javanese script|ECMAScript}}
{{pp-semi-indef|small=yes}}
 
{{Use dmy dates|date=March 2024}}
{{Infobox programming language
| name = JavaScript
| logo = File<!-- Do not add unofficial logo, per [[Talk:JavaScript-/Archive 5#Why is the unofficial logo.png present?]] -->
| logo alt =
| screenshot = JavaScript code.png
| paradigm = [[Multi-paradigm]]: [[object-oriented programming|object-oriented]] ([[prototype-based programming|prototype-based]]), [[imperative programming|imperative]], [[functional programming|functional]], [[event-driven programming|event-driven]]{{Sfn|Flanagan|2011|pp =1–2}}
| screenshot caption = Screenshot of JavaScript source code
| designer = [[Brendan Eich]]
| paradigms = [[Multi-paradigm]]: [[Event-driven programming|event-driven]], [[Functional programming|functional]], [[Imperative programming|imperative]], [[Procedural programming|procedural]], [[Object-oriented programming|object-oriented]]
| developer = [[Netscape|Netscape Communications Corporation]], [[Mozilla Foundation]], [[Ecma International]]
| memory management = [[Garbage collection (computer science)|Garbage collected]]
| typing = [[Dynamic typing|Dynamic]], [[Duck typing|duck]]
| family = [[ECMAScript]]
| implementations = [[V8 (JavaScript engine)|V8]], [[JavaScriptCore]], [[SpiderMonkey (JavaScript engine)|SpiderMonkey]], [[Chakra (JScript engine)|Chakra]]
| designers = [[Brendan Eich]] of [[Netscape]] first; then others contributed to [[ECMAScript]] standard
| influenced = [[ActionScript]], [[AtScript]], [[CoffeeScript]], [[Dart (programming language)|Dart]], [[JScript .NET]], [[LiveScript]], [[Objective-J]], [[Opa (programming language)|Opa]], [[Perl 6]], [[QML]], [[TypeScript]]
| typing = [[Dynamic typing|Dynamic]], [[Strong and weak typing|weak]], [[Duck typing|duck]]
| scope = [[Scope (computer science)|lexical]]
| released = {{Start date and age|1995|12|04|df=y}}<ref name="press_release">{{Cite press release |url=https://wp.netscape.com/newsref/pr/newsrelease67.html |archive-url=https://web.archive.org/web/20070916144913/https://wp.netscape.com/newsref/pr/newsrelease67.html |archive-date=2007-09-16 |title=Netscape and Sun announce JavaScript, the Open, Cross-platform Object Scripting Language for Enterprise Networks and the Internet |date=December 4, 1995}}</ref>
| latest release version = {{wikidata|property|edit|reference|P548=Q2804309|P348}}
| latest release date = {{start date and age|{{wikidata|qualifier|single|P548=Q2804309|P348|P577}}}}
| latest preview version = {{wikidata|property|edit|reference|P548=Q51930650|P348}}
| latest preview date = {{start date and age|{{wikidata|qualifier|single|P548=Q51930650|P348|P577}}}}
| license =
| file extensions = <code>.js</code> • <code>.mjs</code> • <code>.cjs</code><ref name="node.js ECMAScript Modules Specification">{{cite web|url=https://github.com/nodejs/node-eps/blob/master/002-es-modules.md|title=nodejs/node-eps|website=GitHub|access-date=2018-07-05|archive-date=2020-08-29|archive-url=https://web.archive.org/web/20200829024713/https://github.com/nodejs/node-eps/blob/master/002-es-modules.md|url-status=live}}</ref>
| File extensions = <code>.js</code>
| Filefile format =
| website = [{{URL|https://developer.mozillaecma-international.org/enpublications-USand-standards/docsstandards/Webecma-262/JavaScript Mozilla]}}
| implementations = [[V8 (JavaScript engine)|V8]], [[JavaScriptCore]], [[SpiderMonkey]];<br/>[[Chakra (JavaScript engine)|Chakra]] (deprecated)
| influenced by = [[Java (programming language)|Java]],<ref name="looklikejava">{{cite book |last1=Seibel |first1=Peter |date=September 16, 2009 |title=Coders at Work: Reflections on the Craft of Programming |publisher=Apress |isbn=978-1-4302-1948-4 |quote=Eich: The immediate concern at Netscape was it must look like Java. |url=https://books.google.com/books?id=nneBa6-mWfgC&q=The+immediate+concern+at+Netscape+was+it+must+look+like+Java.&pg=PA141 |access-date=December 25, 2018 |url-status=live |archive-url=https://web.archive.org/web/20201224233514/https://books.google.com/books?id=nneBa6-mWfgC&q=The+immediate+concern+at+Netscape+was+it+must+look+like+Java.&pg=PA141 |archive-date=December 24, 2020}}</ref><ref name="origin"/> [[Scheme (programming language)|Scheme]],<ref name="origin"/> [[Self (programming language)|Self]],<ref>{{cite web |url=https://brendaneich.com/2008/04/popularity/ |title = Popularity – Brendan Eich}}</ref> [[AWK]],<ref>{{cite web |title=Brendan Eich: An Introduction to JavaScript, JSConf 2010 |website=[[YouTube]] |date=20 January 2013 |quote=Eich: "function", eight letters, I was influenced by AWK. |url=https://www.youtube.com/watch?v=1EyRscXrehw |access-date=November 25, 2019 |page=22m |url-status=live |archive-url=https://web.archive.org/web/20200829024704/https://www.youtube.com/watch?v=1EyRscXrehw |archive-date=August 29, 2020}}</ref> [[HyperTalk]]<ref>{{cite book |last1=Eich |first1=Brendan |author1-link=Brendan Eich |chapter=Foreword |editor1-last=Goodman |editor1-first=Danny |editor1-link=Danny Goodman |year=1998 |title=JavaScript Bible |edition=3rd |publisher=[[John Wiley & Sons]] |isbn=0-7645-3188-3 |lccn=97078208 |oclc=38888873 |ol=712205M |url-access=registration |url=https://archive.org/details/javascriptbible000good}}</ref>
| influenced = [[ActionScript]], [[ArkTS]], [[AssemblyScript]], [[CoffeeScript]], [[Dart (programming language)|Dart]], [[Haxe]], [[JS++]], [[Opa (programming language)|Opa]], [[TypeScript]]
| wikibooks = JavaScript
| year = {{start date and age|1995|12|04}}<ref name="press_release">[https://web.archive.org/web/20070916144913/http://wp.netscape.com/newsref/pr/newsrelease67.html Press release announcing JavaScript], "Netscape and Sun announce JavaScript", PR Newswire, December 4, 1995</ref>
| latest_release_version = ECMAScript 2017<ref name="auto">{{cite web|url=https://www.ecma-international.org/publications/standards/Ecma-262.htm|title=Standard ECMA-262|publisher=Ecma International|date=2017-07-03}}</ref>
| latest_release_date = {{start date and age|2017|6}}
| latest_preview_version =
| latest_preview_date =
| influenced_by = [[Lua (programming language)|Lua]], [[Scheme (programming language)|Scheme]], [[Perl]], [[Self (programming language)|Self]], [[Java (programming language)|Java]], [[C (programming language)|C]], [[Python (programming language)|Python]], [[AWK]], [[HyperTalk]] <!--True for first JavaScript? Or only ECMAScript – later JavaScript versions-->
}}
{{Infobox file format
| name = JavaScript
| logo =
| screenshot =
| caption =
| extension = .js
| mime = {{flatlist|
* <code>application/javascript</code>
* <code>text/javascript</code>&nbsp;(obsolete)<ref>{{cite web|url=http://www.apps.ietf.org/rfc/rfc4329.html#sec-7.1|title=RFC 4329|publisher=Apps.ietf.org|archive-url=https://web.archive.org/web/20140316122853/http://www.apps.ietf.org/rfc/rfc4329.html#sec-7|archive-date=2014-03-16|access-date=16 February 2016|dead-url=yes}}</ref>
}}
|_nomimecode = y
| type code =
| uniform type = com.netscape.javascript-source
<ref>{{cite web
| publisher = Apple Inc.
| url = https://developer.apple.com/mac/library/documentation/Miscellaneous/Reference/UTIRef/Articles/System-DeclaredUniformTypeIdentifiers.html
| title = System-Declared Uniform Type Identifiers
| work = Mac OS X Reference Library
| accessdate = 2010-03-05}}</ref>
| magic =
| owner =
| released =
| latest release version =
| latest release date =
| genre = [[Scripting language]]
| container for =
| contained by =
| extended from =
| extended to =
| standard =
}}
{{JavaScriptSidebar}}
 
'''JavaScript''' ('''JS'''){{efn|{{IPAc-en|ˈ|dʒ|ɑː|v|ə|s|k|r|ɪ|p|t|audio=LL-Q1860 (eng)-Flame, not lame-JavaScript.wav}}}} is a [[programming language]] and core technology of the [[web platform]], alongside [[HTML]] and [[CSS]]. <!--don't add dating or decimals: it'll remain 99% indefinitely-->Ninety-nine percent of [[website]]s on the [[World Wide Web]] use JavaScript on the [[Client (computing)|client]] side for [[Web page|webpage]] behavior.<ref name="deployedstats">{{cite web |title=Usage Statistics of JavaScript as Client-side Programming Language on Websites |url=https://w3techs.com/technologies/details/cp-javascript |access-date=2024-02-27 |website=W3Techs }}</ref>
'''JavaScript''' ({{IPAc-en|ˈ|dʒ|ɑː|v|ə|ˌ|s|k|r|ɪ|p|t}}),<ref>{{cite web | url= http://dictionary.reference.com/browse/javascript | title= JavaScript | publisher= William Collins Sons & Co | work= Collins English Dictionary – Complete & Unabridged 2012 Digital Edition | date= 2012 | accessdate= 21 August 2015}}</ref> often abbreviated as '''JS''', is a [[High-level programming language|high-level]], [[Interpreted language|interpreted]] [[programming language]]. It is a language which is also characterized as [[dynamic programming language|dynamic]], [[Weak typing|weakly typed]], [[prototype-based programming|prototype-based]] and [[Multi-paradigm programming language|multi-paradigm]].
 
[[Web browser]]s have a dedicated [[JavaScript engine]] that executes the client [[Source code|code]]. These engines are also utilized in some [[Server (computing)|servers]] and a variety of [[Application software|apps]]. The most popular [[runtime system]] for non-browser usage is [[Node.js]]{{cn|date=August 2025}}.
Alongside [[HTML]] and [[CSS]], JavaScript is one of the three core technologies of the [[World Wide Web]].{{Citation needed|date=April 2018}} It is used to make dynamic webpages interactive and provide online programs, including video games. The majority of [[Website|websites]] employ it{{Citation needed|date=April 2018}}, and all modern [[Web browser|web browsers]] support it without the need for [[Browser extension|plug-ins]] by means of a built-in [[JavaScript engine]]. Each of the many JavaScript engines represent a different implementation of JavaScript, all based on the [[ECMAScript]] specification, with some engines not supporting the spec fully, and with many engines supporting additional features beyond ECMA.
 
JavaScript is a [[High-level programming language|high-level]], often [[Just-in-time compilation|just-in-time–compiled]] language that conforms to the [[ECMAScript]] standard.<ref name="tc39">{{cite web|title=ECMAScript 2020 Language Specification|url=https://tc39.es/ecma262/#sec-overview|url-status=live|archive-url=https://web.archive.org/web/20200508053013/https://tc39.es/ecma262/#sec-overview|archive-date=2020-05-08|access-date=2020-05-08}}</ref> It has [[dynamic typing]], [[Prototype-based programming|prototype-based]] [[object-oriented programming|object-orientation]], and [[first-class function]]s. It is [[Programming paradigm|multi-paradigm]], supporting [[Event-driven programming|event-driven]], [[functional programming|functional]], and [[imperative programming|imperative]] [[programming paradigm|programming styles]]. It has [[application programming interface]]s (APIs) for working with text, dates, [[regular expression]]s, standard [[data structure]]s, and the [[Document Object Model]] (DOM).
As a multi-paradigm language, JavaScript supports [[Event-driven programming|event-driven]], [[functional programming|functional]], and [[imperative programming|imperative]] (including [[Object-oriented programming|object-oriented]] and [[Prototype-based programming|prototype-based]]) [[programming paradigm | programming style]]s. It has an [[Application programming interface|API]] for working with text, [[Array data type|arrays]], dates, [[regular expression]]s, and basic manipulation of the [[Document_Object_Model|DOM]], but the language itself does not include any [[Input/output|I/O]], such as networking, storage, or graphics facilities, relying for these upon the host environment in which it is embedded.
 
The ECMAScript standard does not include any [[input/output]] (I/O), such as [[computer network|networking]], [[data storage|storage]], or [[computer graphics|graphics]] facilities. In practice, the web browser or other runtime system provides JavaScript APIs for I/O.
Initially only implemented [[client-side]] in web browsers, JavaScript engines are now embedded in many other types of host software, including [[server-side]] in web servers and databases, and in non-web programs such as word processors and [[Portable Document Format|PDF]] software, and in runtime environments that make JavaScript available for writing mobile and desktop applications, including desktop widgets.
 
Although there are strong outward similarities between JavaScript and [[Java (programming language)|Java]], includingand languageJavaScript are similar in name, and [[Syntax (programming languages)|syntax]], and respective [[standard library|standard libraries]], the two languages are distinct and differ greatly in design; JavaScript was influenced by programming languages such as [[Self (programming language)|Self]] and [[Scheme (programming language)|Scheme]].<ref>
{{cite web
|title = ECMAScript Language Overview
|url = http://www.ecmascript.org/es4/spec/overview.pdf
|format = PDF
|page = 4
|date = 2007-10-23
|accessdate = 2009-05-03
|deadurl = yes
|archiveurl = https://www.webcitation.org/5rBiWD4P6?url=http://www.ecmascript.org/es4/spec/overview.pdf
|archivedate = 2010-07-13
|df =
}}
</ref>
 
== History ==
=== BeginningsCreation at Netscape ===
The first popular [[web browser]] with a [[graphical user interface]], [[Mosaic (web browser)|Mosaic]], was released in 1993. The lead developers of Mosaic then founded the [[Netscape]] corporation, which released a more polished browser, [[Netscape Navigator]], in 1994. This quickly became the most-used.<ref>{{cite web|url=https://www.mwdwebsites.com/nj-web-design-web-browsers.html|title=The Evolution of the Web Browsers|last=Enzer|first=Larry|date=August 31, 2018|website=Monmouth Web Developers|access-date=August 31, 2018|archive-date=August 31, 2018|archive-url=https://web.archive.org/web/20180831174847/https://www.mwdwebsites.com/nj-web-design-web-browsers.html|url-status=dead}}</ref>
In 1993, the [[National Center for Supercomputing Applications]] (NCSA), a unit of the [[University of Illinois at Urbana–Champaign|University of Illinois at Urbana-Champaign]], released [[Mosaic (web browser)|NCSA Mosaic]], the first popular graphical [[Web browser]], which played an important part in expanding the growth of the nascent [[World Wide Web]]. In 1994, a company called [[Netscape|Mosaic Communications]] was founded in [[Mountain View, California]] and employed many of the original NCSA Mosaic authors to create [[Netscape Navigator|Mosaic Netscape]]. However, it intentionally shared no code with NCSA Mosaic. The internal codename for the company's browser was Mozilla, which stood for "Mosaic killer", as the company's goal was to displace NCSA Mosaic as the world's number one web browser. The first version of the Web browser, Mosaic Netscape 0.9, was released in late 1994. Within four months it had already taken three-quarters of the browser market and became the main browser for the Internet in the 1990s. To avoid trademark ownership problems with the NCSA, the browser was subsequently renamed Netscape Navigator in the same year, and the company took the name Netscape Communications. Netscape Communications realized that the Web needed to become more dynamic. [[Marc Andreessen]], the founder of the company believed that [[HTML]] needed a "glue language" that was easy to use by Web designers and part-time programmers to assemble components such as images and plugins, where the code could be written directly in the Web page markup.
 
In 1995, Netscape Communications recruited [[Brendan Eich]] with the goal of embedding the [[Scheme (programming language)|Scheme]] programming language into its Netscape Navigator.<ref>{{cite web|url=http://speakingjs.com/es5/ch04.html|title=Chapter 4. How JavaScript Was Created}}</ref> Before he could get started, Netscape Communications collaborated with [[Sun Microsystems]] to include in Netscape Navigator Sun's more static programming language [[Java (programming language)|Java]], in order to compete with [[Microsoft Outlook|Microsoft]] for user adoption of Web technologies and platforms.<ref>{{cite journal | last=Severance | first=Charles | date=February 2012 | title=JavaScript: Designing a Language in 10 Days | journal=Computer | volume=45 | issue=2 | pages=7–8 | publisher=IEEE Computer Society | url=http://www.computer.org/csdl/mags/co/2012/02/mco2012020007-abs.html | accessdate=23 March 2013 | doi=10.1109/MC.2012.57 }}</ref> Netscape Communications then decided that the scripting language they wanted to create would complement Java and should have a similar syntax, which excluded adopting other languages such as [[Perl]], [[Python (programming language)|Python]], [[Tcl|TCL]], or Scheme. To defend the idea of JavaScript against competing proposals, the company needed a prototype. Eich wrote one in 10 days, in May 1995.
 
Although it was developed under the name '''Mocha''', the language was officially called '''LiveScript''' when it first shipped in beta releases of Netscape Navigator 2.0 in September 1995, but it was renamed '''JavaScript'''<ref name="press_release" /> when it was deployed in the Netscape Navigator 2.0 beta 3 in December.<ref name="techvision">{{cite web | archiveurl=https://web.archive.org/web/20080208124612/http://wp.netscape.com/comprod/columns/techvision/innovators_be.html | archivedate=2008-02-08 | title=TechVision: Innovators of the Net: Brendan Eich and JavaScript | publisher=web.archive.org | url=http://wp.netscape.com/comprod/columns/techvision/innovators_be.html }}</ref> The final choice of name caused confusion, giving the impression that the language was a spin-off of the Java programming language, and the choice has been characterized<ref>{{Citation|last=Fin JS|title=Brendan Eich - CEO of Brave|date=2016-06-17|url=https://www.youtube.com/watch?v=XOmhtfTrRxc&feature=youtu.be&t=2m5s|accessdate=2018-02-07}}</ref> as a marketing ploy by Netscape to give JavaScript the cachet of what was then the hot new Web programming language.
 
During these formative years of the Web, [[web page]]s could only be static, lacking the capability for dynamic behavior after the page was loaded in the browser. There was a desire in the flourishing web development scene to remove this limitation, so in 1995, Netscape decided to add a [[programming language]] to Navigator. They pursued two routes to achieve this: collaborating with [[Sun Microsystems]] to embed the [[Java (programming language)|Java]] language, while also hiring [[Brendan Eich]] to embed the [[Scheme (programming language)|Scheme]] language.<ref name="origin">{{cite web|url=https://exploringjs.com/es5/ch04.html|title=Chapter 4. How JavaScript Was Created|website=speakingjs.com|access-date=2017-11-21|archive-date=2020-02-27|archive-url=https://web.archive.org/web/20200227184037/https://speakingjs.com/es5/ch04.html|url-status=live}}</ref>
There is a common misconception that JavaScript was influenced by an earlier Web page scripting language developed by [[Openwave|Nombas]] named Cmm (not to be confused with the later [[C--]] created in 1997).<ref>{{cite web |url=http://archive.oreilly.com/pub/a/oreilly//news/languageposter_0504.html |title=The History of Programming Languages |publisher=O'Reilly Media |date=2004 |website=oreilly.com |access-date=16 July 2016}}</ref><ref>{{cite web |url=http://media.wiley.com/product_data/excerpt/88/07645790/0764579088.pdf |title=What Is JavaScript? |publisher=Wiley |website=wiley.com |access-date=16 July 2016}}</ref> Brendan Eich, however, had never heard of Cmm before he created LiveScript.<ref>{{cite web |url=http://www.quora.com/Brent-Noorda/answers/ECMA |title=Brent Noorda's Answers on ECMA |last=Noorda |first=Brent |date=21 September 2013 |website=quora.com |access-date=16 July 2016}}</ref> Nombas did pitch their embedded Web page scripting to Netscape, though Web page scripting was not a new concept, as shown by the [[ViolaWWW]] Web browser.<ref>{{cite web |url=http://www.brent-noorda.com/nombas/history/HistoryOfNombas.html#h.yal3k216ii2r |title=History of Nombas |last=Noorda |first=Brent |date=24 June 2010 |website=brent-noorda.com |access-date=16 July 2016}}</ref> Nombas later switched to offering JavaScript instead of Cmm in their ScriptEase product and was part of the TC39 group that standardized ECMAScript.<ref>{{cite web |url=https://brendaneich.com/2011/06/new-javascript-engine-module-owner/ |title=New JavaScript Engine Module Owner |last=Eich |first=Brendan |date=21 June 2011 |website=brendaneich.com |access-date=16 July 2016}}</ref>
 
The goal was a "language for the masses",<ref name="EichVideo" /> "to help nonprogrammers create dynamic, interactive [[website|Web sites]]".<ref>"Netscape Communications Corp.", Browser enhancements. Encyclopædia Britannica 2006 Ultimate Reference Suite DVD</ref> Netscape management soon decided that the best option was for Eich to devise a new language, with syntax similar to Java and less like Scheme or other extant [[scripting language]]s.<ref name="looklikejava" /><ref name="origin" /> Although the new language and its [[Interpreter (computing)|interpreter]] implementation were called LiveScript when first shipped as part of a Navigator [[beta software|beta]] in September 1995, the name was changed to JavaScript for the official release in December.<ref name="origin" /><ref name="press_release" /><ref name="techvision">{{cite web | archive-url=https://web.archive.org/web/20080208124612/https://wp.netscape.com/comprod/columns/techvision/innovators_be.html | archive-date=February 8, 2008 | title=TechVision: Innovators of the Net: Brendan Eich and JavaScript | url=https://wp.netscape.com/comprod/columns/techvision/innovators_be.html }}</ref><ref name="wired2024">{{cite magazine |last1=Han |first1=Sheon |title=JavaScript Runs the World—Maybe Even Literally |url=https://www.wired.com/story/javascript-runs-the-world-maybe-literally/ |magazine=Wired |date=4 March 2024 |access-date=21 August 2024}}</ref>
=== Server-side JavaScript ===
In December 1995, soon after releasing JavaScript for browsers, Netscape introduced an implementation of the language for [[server-side scripting]] with [[Netscape Enterprise Server]].<ref>{{cite web |url=http://docs.oracle.com/cd/E19957-01/816-6411-10/contents.htm |title=Server-Side JavaScript Guide |publisher=Netscape Communications Corporation |date=11 December 1998 |website=oracle.com |accessdate=2016-07-16|author=Netscape Communications Corporation}}</ref>
 
The choice of the ''JavaScript'' name has caused confusion, implying that it is directly related to Java. At the time, the [[Dot-com bubble|dot-com boom]] had begun and Java was a popular new language, so Eich considered the JavaScript name a marketing ploy by Netscape.<ref name="EichVideo">{{Citation|last=Fin JS|title=Brendan Eich&nbsp;– CEO of Brave|date=June 17, 2016|url=https://www.youtube.com/watch?v=XOmhtfTrRxc |website=YouTube |access-date=February 7, 2018 }}</ref>
Since the mid-2000s, additional server-side JavaScript implementations have been introduced, such as [[Node.js]] in 2009.<ref>{{cite web |url=http://readwrite.com/2009/12/17/server-side_javascript_back_with_a_vengeance/ |title=Server-Side JavaScript, Back with a Vengeance |date=17 December 2009 |website=readwrite.com |accessdate=2016-07-16|author=Mahemoff, Michael}}</ref>
 
=== Adoption by Microsoft ===
[[Microsoft]] debuted [[Internet Explorer]] in 1995, leading to a [[browser war]] with Netscape. On the JavaScript front, Microsoft created its own [[Interpreter (computing)|interpreter]] called [[JScript]].<ref name="sjsch5">{{cite web |title=Chapter 5. Standardization: ECMAScript |url=https://speakingjs.com/es5/ch05.html |website=speakingjs.com |access-date=1 November 2021 |archive-date=1 November 2021 |archive-url=https://web.archive.org/web/20211101184346/http://speakingjs.com/es5/ch05.html |url-status=dead }}</ref>
Microsoft script technologies including [[VBScript]] and [[JScript]] were released in 1996. JScript, a reverse-engineered implementation of Netscape's JavaScript, was part of [[Internet Explorer 3]]. JScript was also available for server-side scripting in [[Internet Information Server]]. Internet Explorer 3 also included Microsoft's first support for CSS and various extensions to HTML, but in each case the implementation was noticeably different to that found in Netscape Navigator at the time.<ref name="O'Reilly-2001">{{cite web |url=http://archive.oreilly.com/pub/a/javascript/2001/04/06/js_history.html |title=JavaScript, How Did We Get Here? |last=Champeon |first=Steve |date=6 April 2001 |website=oreilly.com |access-date=16 July 2016}}</ref><ref>{{cite web |url=http://news.microsoft.com/1996/05/29/microsoft-internet-explorer-3-0-beta-now-available/ |title=Microsoft Internet Explorer 3.0 Beta Now Available |publisher=Microsoft |date=29 May 1996 |website=microsoft.com |access-date=16 July 2016}}</ref> These differences made it difficult for designers and programmers to make a single website work well in both browsers, leading to the use of "best viewed in Netscape" and "best viewed in Internet Explorer" logos that characterized these early years of the [[browser wars]].<ref>{{cite web |url=http://www.technologizer.com/2010/09/16/the-unwelcome-return-of-best-viewed-with-internet-explorer/ |title=The Unwelcome Return of "Best Viewed with Internet Explorer" |last=McCracken |first=Harry |date=16 September 2010 |website=technologizer.com |access-date=16 July 2016}}</ref> JavaScript began to acquire a reputation for being one of the roadblocks to a cross-platform and standards-driven Web. Some developers took on the difficult task of trying to make their sites work in both major browsers, but many could not afford the time.<ref name="O'Reilly-2001" /> With the release of [[Internet Explorer 4]], Microsoft introduced the concept of [[Dynamic HTML]], but the differences in language implementations and the different and proprietary [[Document Object Model]]s remained and were obstacles to widespread take-up of JavaScript on the Web.<ref name="O'Reilly-2001" />
 
Microsoft first released JScript in 1996, alongside initial support for [[CSS]] and extensions to [[HTML]]. Each of these [[implementation]]s was noticeably different from their counterparts in [[Netscape Navigator]].<ref name="O'Reilly-2001">{{cite web |url=https://archive.oreilly.com/pub/a/javascript/2001/04/06/js_history.html |title=JavaScript, How Did We Get Here? |last=Champeon |first=Steve |date=April 6, 2001 |website=oreilly.com |access-date=July 16, 2016 |archive-url=https://web.archive.org/web/20160719020828/https://archive.oreilly.com/pub/a/javascript/2001/04/06/js_history.html |archive-date=July 19, 2016 |url-status=dead}}</ref><ref>{{cite web |url=https://news.microsoft.com/1996/05/29/microsoft-internet-explorer-3-0-beta-now-available/ |title=Microsoft Internet Explorer 3.0 Beta Now Available |publisher=Microsoft |date=May 29, 1996 |website=microsoft.com |access-date=July 16, 2016 |archive-date=November 24, 2020 |archive-url=https://web.archive.org/web/20201124154053/https://news.microsoft.com/1996/05/29/microsoft-internet-explorer-3-0-beta-now-available/ |url-status=live }}</ref> These differences made it difficult for developers to make their websites work well in both browsers, leading to widespread use of "best viewed in Netscape" and "best viewed in Internet Explorer" logos for several years.<ref name="O'Reilly-2001" /><ref>{{cite web |url=https://www.technologizer.com/2010/09/16/the-unwelcome-return-of-best-viewed-with-internet-explorer/ |title=The Unwelcome Return of "Best Viewed with Internet Explorer" |last=McCracken |first=Harry |date=September 16, 2010 |website=technologizer.com |access-date=July 16, 2016 |archive-date=June 23, 2018 |archive-url=https://web.archive.org/web/20180623192402/https://www.technologizer.com/2010/09/16/the-unwelcome-return-of-best-viewed-with-internet-explorer/ |url-status=live }}</ref>
=== Standardization ===
In November 1996, Netscape submitted JavaScript to [[Ecma International]] to carve out a standard specification, which other browser vendors could then implement based on the work done at Netscape. This led to the official release of the language specification [[ECMAScript]] published in the first edition of the ECMA-262 standard in June 1997, with JavaScript being the most well known of the implementations. [[ActionScript]] and [[JScript]] are other well-known implementations of ECMAScript.
 
=== The rise of JScript ===
The standards process continued in cycles, with the release of ECMAScript 2 in June 1998, which brings some modifications to conform to the ISO/IEC 16262 international standard. The release of ECMAScript 3 followed in December 1999, which is the baseline for modern day JavaScript. The original ECMAScript 4 work led by Waldemar Horwat (then at Netscape, now at [[Google]]) started in 2000 and at first, [[Microsoft]] seemed to participate and even implemented some of the proposals in their [[JScript .NET]] language.
{{Quote box|[[Brendan Eich]] later said of this period: "It's still kind of a [[sidekick]] language. It's considered slow or annoying. People do [[Pop-up ad|pop-ups]] or those scrolling messages in the old [[status bar]] at the bottom of your old [[web browser|browser]]."<ref name="EichVideo" />|width=30%}}
 
In November 1996, [[Netscape]] submitted JavaScript to [[Ecma International]], as the starting point for a standard specification that all browser vendors could conform to. This led to the official release of the first [[ECMAScript]] language specification in June 1997.
Over time it was clear though that Microsoft had no intention of cooperating or implementing proper JavaScript in Internet Explorer, even though they had no competing proposal and they had a partial (and diverged at this point) implementation on the [[.NET]] server side. So by 2003, the original ECMAScript 4 work was mothballed.
 
The standards process continued for a few years, with the release of ECMAScript 2 in June 1998 and ECMAScript 3 in December 1999. Work on ECMAScript 4 began in 2000.<ref name="sjsch5" />
The next major event was in 2005, with two major happenings in JavaScript's history. First, Brendan Eich and Mozilla rejoined Ecma International as a not-for-profit member and work started on [[ECMAScript for XML]] (E4X), the ECMA-357 standard, which came from ex-Microsoft employees at [[BEA Systems]] (originally acquired as Crossgain). This led to working jointly with [[Macromedia]] (later acquired by [[Adobe Systems]]), who were implementing E4X in ActionScript 3 (ActionScript 3 was a fork of original ECMAScript 4).
 
However, the effort to fully standardize the language was undermined by Microsoft gaining an increasingly dominant position in the browser market. By the early 2000s, [[Internet Explorer]]'s market share reached 95%.<ref name="searchenginejournal.com">{{cite news |last1=Baker |first1=Loren |date=November 24, 2004 |url=https://www.searchenginejournal.com/mozilla-firefox-internet-browser-market-share-gains-to-74/1082/ |title=Mozilla Firefox Internet Browser Market Share Gains to 7.4% |work=Search Engine Journal |access-date=May 8, 2021 |archive-date=May 7, 2021 |archive-url=https://web.archive.org/web/20210507013607/https://www.searchenginejournal.com/mozilla-firefox-internet-browser-market-share-gains-to-74/1082/ |url-status=live}}</ref> This meant that [[JScript]] became the de facto standard for [[client-side scripting]] on the Web.
So, along with Macromedia, work restarted on ECMAScript 4 with the goal of standardizing what was in ActionScript 3. To this end, Adobe Systems released the ActionScript Virtual Machine 2, code named [[Tamarin (software)|Tamarin]], as an [[open source]] project. But Tamarin and ActionScript 3 were too different from web JavaScript to converge, as was realized by the parties in 2007 and 2008.
 
Microsoft initially participated in the standards process and implemented some proposals in its JScript language, but eventually it stopped collaborating on ECMA work. Thus ECMAScript 4 was mothballed.
Alas, there was still turmoil between the various players; [[Douglas Crockford]]—then at [[Yahoo!]]—joined forces with Microsoft in 2007 to oppose ECMAScript 4, which led to the ECMAScript 3.1 effort. The development of ECMAScript 4 was never completed, but that work influenced subsequent versions.<ref>{{cite web|url=http://www.ecmascript.org/docs.php|title=Documentation|last=|first=|date=|website=ecmascript.org|archive-url=https://web.archive.org/web/20110426141932/http://www.ecmascript.org/docs.php|archive-date=2011-04-26|dead-url=|access-date=16 July 2016|quote=development of a Fourth Edition was not completed, that work influenced Fifth Edition}}</ref>
 
=== Growth and standardization ===
While all of this was happening, the open source and developer communities set to work to revolutionize what could be done with JavaScript. This community effort was sparked in 2005 when [[Jesse James Garrett]] released a white paper in which he coined the term [[Ajax (programming)|Ajax]], and described a set of technologies, of which JavaScript was the backbone, used to create web applications where data can be loaded in the background, avoiding the need for full page reloads and leading to more dynamic applications. This resulted in a renaissance period of JavaScript usage spearheaded by open source libraries and the communities that formed around them, with libraries such as [[Prototype JavaScript Framework|Prototype]], [[jQuery]], [[Dojo Toolkit]], [[MooTools]], and others being released.
{{Plain image with caption|Logo of TC39.svg|Logo of [[Ecma International]] Technical Committee 39 who is responsible for maintaining the standard|150px}}
During the period of [[Internet Explorer]] dominance in the early 2000s, client-side scripting was stagnant. This started to change in 2004, when the successor of Netscape, [[Mozilla]], released the [[Firefox]] browser. Firefox was well received by many, taking significant market share from Internet Explorer.<ref>{{cite news |url=https://news.bbc.co.uk/2/hi/business/4508897.stm |title=The assault on software giant Microsoft |last=Weber |first=Tim |date=May 9, 2005 |work=[[BBC News]] |archive-url=https://web.archive.org/web/20170925233936/https://news.bbc.co.uk/2/hi/business/4508897.stm |archive-date=September 25, 2017}}</ref>
 
In 2005, Mozilla joined ECMA International, and work started on the [[ECMAScript for XML]] (E4X) standard. This led to Mozilla working jointly with [[Macromedia]] (later acquired by [[Adobe Systems]]), who were implementing E4X in their ActionScript 3 language, which was based on an ECMAScript 4 draft. The goal became standardizing ActionScript 3 as the new ECMAScript 4. To this end, Adobe Systems released the [[Tamarin (software)|Tamarin]] implementation as an [[Open-source model|open source]] project. However, Tamarin and ActionScript 3 were too different from established client-side scripting, and without cooperation from Microsoft, ECMAScript 4 never reached fruition.
In July 2008, the disparate parties on either side came together in Oslo. This led to the eventual agreement in early 2009 to rename ECMAScript 3.1 to ECMAScript 5 and drive the language forward using an agenda that is known as Harmony. ECMAScript 5 was finally released in December 2009.
 
Meanwhile, very important developments were occurring in open-source communities not affiliated with ECMA work. In 2005, [[Jesse James Garrett]] released a white paper in which he coined the term [[Ajax (programming)|Ajax]] and described a set of technologies, of which JavaScript was the backbone, to create [[web application]]s where data can be loaded in the background, avoiding the need for full page reloads. This sparked a renaissance period of JavaScript, spearheaded by open-source libraries and the communities that formed around them. Many new libraries were created, including [[jQuery]], [[Prototype JavaScript Framework|Prototype]], [[Dojo Toolkit]], and [[MooTools]].
In June 2011, ECMAScript 5.1 was released to fully align with the third edition of the ISO/IEC 16262 international standard. ECMAScript 2015 was released in June 2015. ECMAScript 2016 was released in June 2016. The current version is ECMAScript 2017, released in June 2017.<ref name="auto"/>
 
[[Google]] debuted its [[Google Chrome|Chrome]] browser in 2008, with the [[V8 (JavaScript engine)|V8]] JavaScript engine that was faster than its competition.<ref>{{cite web|url=https://www.pcgameshardware.com/aid,687738/Big-browser-comparison-test-Internet-Explorer-vs-Firefox-Opera-Safari-and-Chrome-Update-Firefox-35-Final/Practice/|title=Big browser comparison test: Internet Explorer vs. Firefox, Opera, Safari and Chrome|work=PC Games Hardware|date=3 July 2009|publisher=Computec Media AG|access-date=June 28, 2010|archive-date=May 2, 2012|archive-url=https://web.archive.org/web/20120502043027/http://www.pcgameshardware.com/aid,687738/Big-browser-comparison-test-Internet-Explorer-vs-Firefox-Opera-Safari-and-Chrome-Update-Firefox-35-Final/Practice/|url-status=live}}</ref><ref>{{cite web | url=https://lifehacker.com/lifehacker-speed-tests-safari-4-chrome-2-and-more-5286869 | title=Lifehacker Speed Tests: Safari 4, Chrome 2 | first=Kevin | last=Purdy | work=[[Lifehacker]] | date=June 11, 2009 | access-date=May 8, 2021 | archive-date=April 14, 2021 | archive-url=https://web.archive.org/web/20210414095403/https://lifehacker.com/lifehacker-speed-tests-safari-4-chrome-2-and-more-5286869 | url-status=live }}</ref> The key innovation was [[just-in-time compilation]] (JIT),<ref>{{cite web|url=https://brendaneich.com/2008/08/tracemonkey-javascript-lightspeed/|title=TraceMonkey: JavaScript Lightspeed, Brendan Eich's Blog|access-date=July 22, 2020|archive-date=December 4, 2015|archive-url=https://web.archive.org/web/20151204091540/https://brendaneich.com/2008/08/tracemonkey-javascript-lightspeed/|url-status=live}}</ref> so other browser vendors needed to overhaul their engines for JIT.<ref>{{cite magazine |title=Mozilla asks, 'Are we fast yet?' |url=https://www.wired.com/2010/09/mozilla-asks-are-we-fast-yet/ |magazine=Wired |access-date=January 18, 2019 |archive-date=June 22, 2018 |archive-url=https://web.archive.org/web/20180622213244/https://www.wired.com/2010/09/mozilla-asks-are-we-fast-yet/ |url-status=live }}</ref>
=== Later developments ===
JavaScript has become one of the most popular programming languages on the Web. Initially, however, many professional programmers denigrated the language because, among other reasons, its target audience consisted of Web authors and other such "amateurs".<ref>{{cite web |url=http://www.crockford.com/javascript/javascript.html |title=JavaScript, The World's Most Misunderstood Programming Language |last=Crockford |first=Douglas |date=2001 |website=crockford.com |access-date=16 July 2016}}</ref> The advent of [[Ajax (programming)|Ajax]] returned JavaScript to the spotlight and brought more professional programming attention. The result was a proliferation of comprehensive [[List of JavaScript libraries|frameworks and libraries]], improved JavaScript programming practices, and increased usage of JavaScript outside Web browsers, as seen by the proliferation of [[Server-side JavaScript]] platforms.
 
In July 2008, these disparate parties came together for a conference in [[Oslo]]. This led to the eventual agreement in early 2009 to combine all relevant work and drive the language forward. The result was the ECMAScript 5 standard, released in December 2009.
In January 2009, the [[CommonJS]] project was founded with the goal of specifying a common standard library mainly for JavaScript development outside the browser.<ref>{{cite web |url=https://arstechnica.com/web/news/2009/12/commonjs-effort-sets-javascript-on-path-for-world-domination.ars |title=CommonJS Effort Sets JavaScript on Path for World Domination |last=Kowal |first=Kris |date=1 December 2009 |website=arstechnica.com |access-date=16 July 2016}}</ref>
 
=== Reaching maturity ===
With the rise of [[single-page application]]s and JavaScript-heavy sites, it is increasingly being used as a compile target for [[source-to-source compiler]]s from both [[Dynamic typing|dynamic languages]] and [[Static typing|static languages]].
Ambitious work on the language continued for several years, culminating in an extensive collection of additions and refinements being formalized with the publication of [[ECMAScript 6]] in 2015.<ref>{{cite web |url=https://es6-features.org/ |title=ECMAScript 6: New Features: Overview and Comparison |website=es6-features.org |access-date=March 19, 2018 |archive-date=March 18, 2018 |archive-url=https://web.archive.org/web/20180318064130/https://es6-features.org/ |url-status=usurped }}</ref>
 
The creation of [[Node.js]] in 2009 by [[Ryan Dahl]] sparked a significant increase in the usage of JavaScript outside of web browsers. Node combines the [[V8 (JavaScript engine)|V8]] engine, an [[event loop]], and [[Input/output|I/O]] [[Application programming interface|APIs]], thereby providing a stand-alone JavaScript runtime system.<ref>[https://books.google.com/books?id=ZH6bpbcrlvYC&q=nodejs Professional Node.js: Building JavaScript Based Scalable Software] {{Webarchive|url=https://web.archive.org/web/20170324021220/https://books.google.com/books?id=ZH6bpbcrlvYC&printsec=frontcover&dq=nodejs&hl=en&sa=X#v=onepage&q=nodejs&f=false |date=2017-03-24 }}, John Wiley & Sons, 01-Oct-2012</ref><ref name="b3">[https://books.google.com/books?id=KGt-FxUEj48C&dq=nodejs&pg=PT24 Sams Teach Yourself Node.js in 24 Hours] {{Webarchive|url=https://web.archive.org/web/20170323192039/https://books.google.com/books?id=KGt-FxUEj48C&pg=PT24&dq=nodejs&hl=en&sa=X#v=onepage&q=nodejs&f=false |date=2017-03-23 }}, Sams Publishing, 05-Sep-2012</ref> As of 2018, Node had been used by millions of developers,<ref>{{cite web |last1=Lawton |first1=George |title=The secret history behind the success of npm and Node |url=https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/The-secret-history-behind-the-success-of-npm-and-Node |website=TheServerSide |access-date=2 August 2021 |date=19 July 2018 |archive-date=2 August 2021 |archive-url=https://web.archive.org/web/20210802165613/https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/The-secret-history-behind-the-success-of-npm-and-Node |url-status=live }}</ref> and [[npm (software)|npm]] had the most modules of any [[package manager]] in the world.<ref>{{cite web |last1=Brown |first1=Paul |title=State of the Union: npm |url=https://www.linux.com/news/state-union-npm/ |website=Linux.com |access-date=2 August 2021 |date=13 January 2017 |archive-date=2 August 2021 |archive-url=https://web.archive.org/web/20210802165614/https://www.linux.com/news/state-union-npm/ |url-status=live }}</ref>
== Trademark ==
"JavaScript" is a [[trademark]] of [[Oracle Corporation]] in the United States.<ref>{{cite web | title=USPTO Copyright entry #75026640|url=http://tarr.uspto.gov/servlet/tarr?regser=serial&entry=75026640|publisher=USPTO}}</ref> It is used under license for technology invented and implemented by Netscape Communications and current entities such as the [[Mozilla Foundation]].<ref>{{cite web | title=Sun Trademarks|url=http://www.sun.com/suntrademarks/|publisher=Sun Microsystems|accessdate=2007-11-08|archiveurl=https://web.archive.org/web/20100528154600/http://www.sun.com/suntrademarks/|archivedate=28 May 2010}}</ref>
 
The ECMAScript draft specification is currently maintained openly on [[GitHub]],<ref name=branscombe /> and editions are produced via regular annual snapshots.<ref name=branscombe>{{cite web |url=https://thenewstack.io/whats-new-es2016/ |title=JavaScript Standard Moves to Yearly Release Schedule; Here is What's New for ES16 |last=Branscombe |first=Mary |date=2016-05-04 |access-date=2021-01-15 |work=The New Stack |archive-date=2021-01-16 |archive-url=https://web.archive.org/web/20210116181757/https://thenewstack.io/whats-new-es2016/ |url-status=live }}</ref> Potential revisions to the language are vetted through a comprehensive proposal process.<ref>{{cite web|url=https://tc39.es/process-document/|title=The TC39 Process|publisher=Ecma International|work=tc39.es|access-date=2021-01-15|archive-date=2021-02-07|archive-url=https://web.archive.org/web/20210207105535/https://tc39.es/process-document/|url-status=live}}</ref><ref>{{cite web |url=https://github.com/tc39/proposals/blob/master/README.md |title=ECMAScript proposals |access-date=2021-01-15 |publisher=TC39 |archive-date=2020-12-04 |archive-url=https://web.archive.org/web/20201204221147/https://github.com/tc39/proposals/blob/master/README.md |url-status=live }}</ref> Now, instead of edition numbers, developers check the status of upcoming features individually.<ref name=branscombe />
== Vanilla JavaScript ==
The terms ''Vanilla JavaScript'' and ''Vanilla JS'' refer to JavaScript not extended by any frameworks or additional libraries. Scripts written in Vanilla JS are plain JavaScript code.<ref>{{Cite web|url=http://vanilla-js.com/|title=Vanilla JS|website=vanilla-js.com|access-date=2017-12-15}}</ref><ref>{{Cite web|url=https://stackoverflow.com/questions/20435653/what-is-vanillajs#20435744|title=What is VanillaJS?|website=stackoverflow.com|access-date=2017-12-15}}</ref>
 
The current JavaScript ecosystem has many [[List of JavaScript libraries|libraries]] and [[web framework|frameworks]], established programming practices, and substantial usage of JavaScript outside of web browsers.<ref name="wired2024" /> Plus, with the rise of [[single-page application]]s and other JavaScript-heavy websites, several [[source-to-source compiler|transpilers]] have been created to aid the development process.<ref name="transpilers" />
== Features ==
The following features are common to all conforming ECMAScript implementations, unless explicitly specified otherwise.
 
=== UniversalTrademark support ===
"JavaScript" is a [[trademark]] of [[Oracle Corporation]] in the United States.<ref>{{cite web |date=1997-05-06 |title=U.S. Trademark Serial No. 75026640 |url=https://tsdr.uspto.gov/#caseNumber=75026640&caseType=SERIAL_NO&searchType=statusSearch |url-status=live |archive-url=https://web.archive.org/web/20210713022850/https://tsdr.uspto.gov/#caseNumber=75026640&caseType=SERIAL_NO&searchType=statusSearch |archive-date=2021-07-13 |access-date=2021-05-08 |website=uspto.gov |publisher=[[United States Patent and Trademark Office]]}}</ref><ref>{{cite web |title=Legal Notices |url=https://www.oracle.com/legal/trademarks.html |url-status=live |archive-url=https://web.archive.org/web/20210605142505/https://www.oracle.com/legal/trademarks.html |archive-date=2021-06-05 |access-date=2021-05-08 |website=oracle.com |publisher=[[Oracle Corporation]]}}</ref> The trademark was originally issued to [[Sun Microsystems]] on 6 May 1997, and was transferred to Oracle when they acquired Sun in 2009.<ref>{{Cite news |title=Oracle to buy Sun in $7.4-bn deal | newspaper=The Economic Times |url=https://economictimes.indiatimes.com/tech/software/oracle-to-buy-sun-in-7-4-bn-deal/articleshow/4427747.cms | date = 21 April 2009}}</ref><ref>{{Cite news |title=Oracle urged again to give up JavaScript trademark |work=The Register |url=https://www.theregister.com/2024/09/17/oracle_urged_to_surrender_javascript_trademark/ |date=17 September 2024 |last1=Claburn |first1=Thomas |access-date=2 February 2025}}</ref>
All modern Web browsers support JavaScript with built-in interpreters.
 
A letter was circulated in September 2024, spearheaded by [[Ryan Dahl]], calling on Oracle to free the JavaScript trademark.<ref>{{Cite news|last=Krill|first=Paul|date=September 20, 2024|title=JavaScript community challenges Oracle's JavaScript trademark|url=https://www.infoworld.com/article/3532457/javascript-community-challenges-oracles-javascript-trademark.html|work=InfoWorld}}</ref> [[Brendan Eich]], the original creator of JavaScript, was among the over 14,000 signatories who supported the initiative.
=== Imperative and structured ===
JavaScript supports much of the [[structured programming]] syntax from [[C (computer language)|C]] (e.g., <tt>if</tt> statements, <tt>while</tt> loops, <tt>switch</tt> statements, <tt>do while</tt> loops, etc.). One partial exception is [[scope (computer science)|scoping]]: JavaScript originally had only [[function scoping]] with <tt>var</tt>. ECMAScript 2015 added keywords <tt>let</tt> and <tt>const</tt> for block scoping, meaning JavaScript now has both function and block scoping. Like C, JavaScript makes a distinction between [[Expression (computer science)|expressions]] and [[Statement (computer science)|statements]]. One syntactic difference from C is [[Defensive semicolon|automatic semicolon insertion]], which allows the semicolons that would normally terminate statements to be omitted.{{Sfn|Flanagan|2006|p=16}}
 
== Website client-side usage ==
=== Dynamic ===
JavaScript is the dominant [[client-side]] [[scripting language]] of the Web, with 99% of all [[website]]s using it for this purpose.<ref name="deployedstats" /> Scripts are embedded in or included from [[HTML]] documents and interact with the [[Document Object Model|DOM]].
; Typing: As with most [[scripting language]]s, JavaScript is [[dynamic typing|dynamically typed]]; a [[type system|type]] is associated with each [[value (computer science)|value]], rather than just with each expression. For example, a [[Variable (programming)|variable]] that is at one time bound to a number may later be re-bound to a [[string (computer science)|string]].<ref>{{cite web|url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures |title=JavaScript data types and data structures - JavaScript &#124; MDN |website=Developer.mozilla.org |date=2017-02-16 |accessdate=2017-02-24}}</ref> JavaScript supports various ways to test the type of an object, including [[duck typing]].{{Sfn|Flanagan|2006|pp=176–178}}
; Run-time evaluation: JavaScript includes an <tt>[[eval]]</tt> function that can execute statements provided as strings at run-time.
 
All major [[web browser]]s have a built-in [[JavaScript engine]] that executes the [[Source code|code]] on the user's device.
=== Prototype-based (object-oriented) ===
JavaScript is almost entirely [[object-based]]. In JavaScript, an [[Object (computer science)|object]] is an [[associative array]], augmented with a prototype (see below); each string key provides the name for an object property, and there are two syntactical ways to specify such a name: dot notation (<tt>obj.x&nbsp;=&nbsp;10</tt>) and bracket notation (<tt>obj['x']&nbsp;=&nbsp;10</tt>). A property may be added, rebound, or deleted at run-time. Most properties of an object (and any property that belongs to an object's prototype inheritance chain) can be enumerated using a <tt>for...in</tt> loop.
 
=== Examples of scripted behavior ===
JavaScript has a small number of built-in objects, including {{mono|Function}} and {{mono|Date}}.
* Loading new [[web page]] content without reloading the page, via [[Ajax (programming)|Ajax]] or a [[WebSocket]]. For example, [[user (computing)|users]] of [[social media]] can send and receive messages without leaving the current page.
* Web page animations, such as fading objects in and out, resizing, and moving them.
* Playing [[browser game]]s.
* Controlling the [[Media player software|playback]] of [[streaming media]].
* Generating [[pop-up ad]]s or alert boxes.
* [[Data validation|Validating]] input values of a [[Form (HTML)|web form]] before the data is sent to a [[web server]].
* Logging data about the user's behavior then sending it to a server. The website owner can use this data for [[Web analytics|analytics]], [[ad tracking]], and [[personalization]].
*Redirecting a user to another page.
* Storing and retrieving data on the user's device, via the [[web storage|storage]] or [[Indexed Database API|IndexedDB]] standards.
 
=== Libraries and frameworks ===
; Prototypes: JavaScript uses [[prototype-based programming|prototypes]] where many other object-oriented languages use [[Class (computer science)|classes]] for [[Inheritance (computer science)|inheritance]].<ref>{{cite web | title=Inheritance and the prototype chain|url=https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Inheritance_and_the_prototype_chain|work=Mozilla Developer Network|publisher=[[Mozilla]]|accessdate=6 April 2013}}</ref> It is possible to simulate many class-based features with prototypes in JavaScript.<ref>{{cite book|last=Herman|first=David|title=Effective JavaScript|year=2013|publisher=Addison-Wesley|isbn=978-0-321-81218-6|page=83}}</ref>
Over 80% of websites use a third-party JavaScript [[Library (computing)|library]] or [[web framework]] as part of their client-side scripting.<ref name="lib_usage">{{cite web|url=https://w3techs.com/technologies/overview/javascript_library|title=Usage statistics of JavaScript libraries for websites|website=W3Techs|access-date=2021-04-09}}</ref>
; Functions as object constructors: Functions double as object constructors, along with their typical role. Prefixing a function call with ''new'' will create an instance of a prototype, inheriting properties and methods from the constructor (including properties from the <tt>Object</tt> prototype).<ref>{{cite book|last=Haverbeke|first=Marijn|title=Eloquent JavaScript|year=2011|publisher=No Starch Press|isbn=978-1-59327-282-1|pages=95–97}}</ref> ECMAScript 5 offers the <tt>Object.create</tt> method, allowing explicit creation of an instance without automatically inheriting from the <tt>Object</tt> prototype (older environments can assign the prototype to <tt>null</tt>).<ref>{{cite web | last=Katz|first=Yehuda|title=Understanding "Prototypes" in JavaScript|url=http://yehudakatz.com/2011/08/12/understanding-prototypes-in-javascript/|accessdate=6 April 2013}}</ref> The constructor's <tt>prototype</tt> property determines the object used for the new object's internal prototype. New methods can be added by modifying the prototype of the function used as a constructor. JavaScript's built-in constructors, such as <tt>Array</tt> or <tt>Object</tt>, also have prototypes that can be modified. While it is possible to modify the <tt>Object</tt> prototype, it is generally considered bad practice because most objects in JavaScript will inherit methods and properties from the <tt>Object</tt> prototype, and they may not expect the prototype to be modified.<ref>{{cite book|last=Herman|first=David|title=Effective JavaScript|year=2013|publisher=Addison-Wesley|isbn=978-0-321-81218-6|pages=125–127}}</ref>
; Functions as methods<!--not sure where to classify this under-->: Unlike many object-oriented languages, there is no distinction between a function definition and a [[method (computer science)|method]] definition. Rather, the distinction occurs during function calling; when a function is called as a method of an object, the function's local ''this'' keyword is bound to that object for that invocation.
 
[[jQuery]] is by far the most-used.<ref name="lib_usage" /> Other notable ones include <!--alphabetically is fair here-->[[Angular (web framework)|Angular]], [[Bootstrap (front-end framework)|Bootstrap]], [[Lodash]], [[Modernizr]], [[React (software)|React]], [[Underscore.js|Underscore]], and [[Vue.js|Vue]].<ref name="lib_usage" /> Multiple options can be used in conjunction, such as jQuery and Bootstrap.<ref>{{cite web |title=Using jQuery with Bootstrap |url=https://clouddevs.com/jquery/web-projects-with-bootstrap/ |website=clouddevs.com |date=10 June 2019 |access-date=17 March 2024}}</ref>
=== Functional ===
A [[Subroutine|function]] is [[first-class function|first-class]]; a function is considered to be an object. As such, a function may have properties and methods, such as <samp>.call()</samp> and <tt>.bind()</tt>.<ref>{{cite web | url=https://es5.github.com/#x15.3.4-toc | title=Properties of the Function Object | publisher=Es5.github.com | accessdate=2013-05-26}}</ref> A ''nested'' function is a function defined within another function. It is created each time the outer function is invoked. In addition, each nested function forms a [[Closure (computer programming)|lexical closure]]: The [[Scope (programming)#Lexical scoping vs. dynamic scoping|lexical scope]] of the outer function (including any constant, local variable, or argument value) becomes part of the internal state of each inner function object, even after execution of the outer function concludes.{{Sfn|Flanagan|2006|p=141}} JavaScript also supports [[anonymous function]]s.
 
However, the term "Vanilla JS" was coined for websites not using any libraries or frameworks at all, instead relying entirely on standard JavaScript functionality.<ref>{{cite web |date=2020-06-16 |title=Vanilla JS |url=https://vanilla-js.com/ |url-status=live |archive-url=https://web.archive.org/web/20200616052335/https://vanilla-js.com/ |archive-date=June 16, 2020 |access-date=June 17, 2020 |website=vanilla-js.com}}</ref>
=== Delegative ===
JavaScript supports implicit and explicit [[Delegation (object-oriented programming)|delegation]].
 
== Other usage{{anchor|Server-side_JavaScript|Uses_outside_web_pages}} ==
; Functions as roles (Traits and Mixins): JavaScript natively supports various function-based implementations of [[Role-oriented programming|Role]]<ref>[http://peterseliger.blogspot.de/2014/04/the-many-talents-of-javascript.html#the-many-talents-of-javascript-for-generalizing-role-oriented-programming-approaches-like-traits-and-mixins The many talents of JavaScript for generalizing Role-Oriented Programming approaches like Traits and Mixins], Peterseliger.blogpsot.de, April 11, 2014.</ref> patterns like [[Traits (computer science)|Traits]]<ref>[http://soft.vub.ac.be/~tvcutsem/traitsjs/ Traits for JavaScript], 2010.</ref><ref>{{cite web|url=https://cocktailjs.github.io/ |title=Home &#124; CocktailJS |website=Cocktailjs.github.io |date= |accessdate=2017-02-24}}</ref> and [[Mixin]]s.<ref>Angus Croll, [http://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/ A fresh look at JavaScript Mixins], published May 31, 2011.</ref> Such a function defines additional behavior by at least one method bound to the <tt>this</tt> keyword within its <tt>function</tt> body. A Role then has to be delegated explicitly via <tt>call</tt> or <tt>apply</tt> to objects that need to feature additional behavior that is not shared via the prototype chain.
The use of JavaScript has expanded beyond its [[web browser]] roots. [[JavaScript engine]]s are now embedded<!--don't link Embedded system here--> in a variety of other software systems, both for [[server-side]] website deployments and non-browser [[application software|applications]].
; Object composition and inheritance: Whereas explicit function-based delegation does cover [[Object composition|composition]] in JavaScript, implicit delegation already happens every time the prototype chain is walked in order to, e.g., find a method that might be related to but is not directly owned by an object. Once the method is found it gets called within this object's context. Thus [[Inheritance (computer science)|inheritance]] in JavaScript is covered by a delegation automatism that is bound to the prototype property of constructor functions.
 
Initial attempts at promoting server-side JavaScript usage were [[Netscape Enterprise Server]] and [[Microsoft]]'s [[Internet Information Services]],<ref>{{cite web |date=December 11, 1998 |title=Server-Side JavaScript Guide |url=https://docs.oracle.com/cd/E19957-01/816-6411-10/contents.htm |url-status=live |archive-url=https://web.archive.org/web/20210311173120/https://docs.oracle.com/cd/E19957-01/816-6411-10/contents.htm |archive-date=March 11, 2021 |access-date=May 8, 2021 |website=oracle.com |publisher=[[Oracle Corporation]]}}</ref><ref>{{cite web|last1=Clinick|first1=Andrew|title=Introducing JScript .NET|url=https://msdn.microsoft.com/en-us/library/ms974588.aspx|website=Microsoft Developer Network|publisher=Microsoft|access-date=April 10, 2018|date=July 14, 2000|quote=[S]ince the 1996 introduction of JScript version 1.0 ... we've been seeing a steady increase in the usage of JScript on the server—particularly in Active Server Pages (ASP)|archive-date=November 10, 2017|archive-url=https://web.archive.org/web/20171110201649/https://msdn.microsoft.com/en-us/library/ms974588.aspx|url-status=live}}</ref> but they were small niches.<ref name="2009server" /> Server-side usage eventually started to grow in the late 2000s, with the creation of [[Node.js]] and [[List of server-side JavaScript implementations|other approaches]].<ref name="2009server">{{cite web |url=https://readwrite.com/2009/12/17/server-side_javascript_back_with_a_vengeance/ |title=Server-Side JavaScript, Back with a Vengeance |date=December 17, 2009 |website=readwrite.com |access-date=July 16, 2016 |author=Mahemoff, Michael |archive-date=June 17, 2016 |archive-url=https://web.archive.org/web/20160617030219/https://readwrite.com/2009/12/17/server-side_javascript_back_with_a_vengeance/ |url-status=live }}</ref>
=== Miscellaneous ===
; Run-time environment: JavaScript typically relies on a run-time environment (e.g., a [[Web browser]]) to provide objects and methods by which scripts can interact with the environment (e.g., a webpage [[Document Object Model|DOM]]). It also relies on the run-time environment to provide the ability to include/import scripts (e.g., [[HTML]] <tt><nowiki><script></nowiki></tt> elements). This is not a language feature per se, but it is common in most JavaScript implementations.
 
[[Electron (software framework)|Electron]], [[Apache Cordova|Cordova]], [[React Native]], and other [[application framework]]s have been used to create many applications with behavior implemented in JavaScript. Other non-browser applications include [[Adobe Acrobat]] support for scripting [[PDF]] documents<ref>{{cite web |date=2009-08-07 |title=JavaScript for Acrobat |url=https://www.adobe.com/devnet/acrobat/javascript.html |url-status=live |archive-url=https://web.archive.org/web/20090807065130/https://www.adobe.com/devnet/acrobat/javascript.html |archive-date=August 7, 2009 |access-date=August 18, 2009 |website=adobe.com}}</ref> and [[GNOME Shell]] extensions written in JavaScript.<ref>{{cite web |last=treitter |date=2013-02-02 |title=Answering the question: "How do I develop an app for GNOME?" |url=https://treitter.livejournal.com/14871.html |url-status=live |archive-url=https://web.archive.org/web/20130211032900/https://treitter.livejournal.com/14871.html |archive-date=2013-02-11 |access-date=2013-02-07 |website=livejournal.com}}</ref>
: JavaScript processes [[Message (computer science)|messages]] from a [[Queue (abstract data type)|queue]] one at a time. Upon loading a new message, JavaScript calls a [[Subroutine|function]] associated with that message, which creates a [[call stack]] frame (the function's [[Parameter (computer programming)|arguments]] and [[local variable]]s). The call stack shrinks and grows based on the function's needs. Upon function completion, when the stack is empty, JavaScript proceeds to the next message in the queue. This is called the [[event loop]], described as "run to completion" because each message is fully processed before the next message is considered. However, the language's [[Concurrency (computer science)|concurrency model]] describes the event loop as [[Asynchronous I/O|non-blocking]]: program [[input/output]] is performed using [[Event (computing)|events]] and [[Callback (computer programming)|callback functions]]. This means, for instance, that JavaScript can process a mouse click while waiting for a database query to return information.<ref>{{cite web|title = Concurrency model and Event Loop|url = https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop|website = Mozilla Developer Network|accessdate = 2015-08-28}}</ref>
 
[[Oracle Corporation|Oracle]] used to provide [[Nashorn (JavaScript engine)| Nashorn]], a JavaScript interpreter, as part of their [[JDK|Java Development Kit (JDK)]] API library along with '''jjs''' a command line interpreter as of JDK version 8. It was removed in JDK 15. As a replacement Oracle offered GraalJS which can also be used with the [[OpenJDK]] which allows one to create and reference Java objects in JavaScript code and add runtime scripting in JavaScript to applications written in Java.<ref> {{cite web |last=Ponge |first=Julien |date=2018-04-19 |title=Oracle Nashorn: A Next-Generation JavaScript Engine for the JVM |website=oracle.com |url=https://www.oracle.com/technical-resources/articles/java/jf14-nashorn.html |publisher=Oracle Corporation |access-date=Feb 17, 2025}} </ref><ref>{{cite web |author=<!-- not stated --> |title=Migration Guide from Nashorn to GraalJS |url=https://www.graalvm.org/latest/reference-manual/js/NashornMigrationGuide/ |website=graalvm.org | access-date=Feb 17, 2025}} </ref><ref>{{cite web |author=<!-- not stated --> |title=GraalJS |url=https://www.graalvm.org/latest/reference-manual/js/ |website=|publisher=GraalVM |access-date=Feb 17, 2025}}</ref><ref>{{cite web |author=<!-- not stated --> |title=Java Interoperability | url=https://docs.oracle.com/en/graalvm/enterprise/21/docs/reference-manual/js/JavaInteroperability/|website=oracle.com|publisher=Oracle |access-date=Feb 17, 2025}}</ref>
; Variadic functions<!--note: this is not a functional programming feature-->: An indefinite number of parameters can be passed to a function. The function can access them through [[formal parameter]]s and also through the local {{mono|arguments}} object. [[Variadic functions]] can also be created by using the <tt>[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind bind]</tt> method.
 
JavaScript has been used in some [[embedded system]]s, usually by leveraging Node.js.<ref>{{cite web |title=Tessel 2... Leverage all the libraries of Node.JS to create useful devices in minutes with Tessel. |url=https://tessel.io/ |url-status=live |archive-url=https://web.archive.org/web/20210526212559/https://tessel.io/ |archive-date=2021-05-26 |access-date=2021-05-08 |website=tessel.io}}</ref><ref>{{cite web |title=Node.js Raspberry Pi GPIO Introduction |url=https://www.w3schools.com/nodejs/nodejs_raspberrypi_gpio_intro.asp |url-status=live |archive-url=https://web.archive.org/web/20210813192938/https://www.w3schools.com/nodejs/nodejs_raspberrypi_gpio_intro.asp |archive-date=2021-08-13 |access-date=2020-05-03 |website=w3schools.com}}</ref><ref>{{cite web |title=Espruino&nbsp;– JavaScript for Microcontrollers |url=https://www.espruino.com/ |url-status=live |archive-url=https://web.archive.org/web/20200501010722/https://www.espruino.com/ |archive-date=2020-05-01 |access-date=2020-05-03 |website=espruino.com}}</ref>
; Array and object literals: Like many scripting languages, arrays and objects ([[associative arrays]] in other languages) can each be created with a succinct shortcut syntax. In fact, these [[Object literal|literals]] form the basis of the [[JSON]] data format.
 
== Execution ==
; Regular expressions: JavaScript also supports [[regular expression]]s in a manner similar to [[Perl]], which provide a concise and powerful syntax for text manipulation that is more sophisticated than the built-in string functions.<ref>{{cite book | last=Haverbeke | first=Marijn | title=Eloquent JavaScript | year=2011 | publisher=No Starch Press|isbn=978-1-59327-282-1|pages=139–149}}</ref>
=== JavaScript engine ===
{{Excerpt|JavaScript engine}}
 
=== Vendor-specificRuntime extensionssystem ===
A JavaScript engine must be embedded within a [[runtime system]] (such as a [[web browser]] or a standalone system) to enable scripts to interact with the broader environment. The runtime system includes the necessary APIs for [[input/output]] operations, such as [[computer network|networking]], [[data storage|storage]], and [[computer graphics|graphics]], and provides the ability to import scripts.
JavaScript is officially managed by [[Mozilla Foundation]], and new language features are added periodically. However, only some [[JavaScript engine]]s support these new features:
* property getter and setter functions (supported by WebKit, Gecko, Opera,<ref>Robert Nyman, [http://robertnyman.com/2009/05/28/getters-and-setters-with-javascript-code-samples-and-demos/ Getters And Setters With JavaScript – Code Samples And Demos], Robertnyman.com, published 29 May 2009, accessed 2 January 2010.</ref> ActionScript, and Rhino)<ref>John Resig, [http://ejohn.org/blog/javascript-getters-and-setters/ JavaScript Getters and Setters], Ejohn.org, 18 July 2007, accessed 2 January 2010</ref>
* conditional <tt>catch</tt> clauses
* iterator protocol (adopted from [[Python (programming language)|Python]])
* shallow [[generator (computer programming)|generators]]-[[coroutine]]s (adopted from Python)
* [[List comprehension|array comprehensions]] and generator expressions (adopted from Python)
* proper block scope via the <tt>let</tt> keyword
* array and object destructuring (limited form of [[pattern matching]])
* concise function expressions (<tt>function(args) expr</tt>)
* [[ECMAScript for XML]] (E4X), an extension that adds native XML support to ECMAScript (unsupported in Firefox since version 21<ref>{{cite web | title=E4X – Archive of obsolete content &#124; MDN|url=https://developer.mozilla.org/en-US/docs/Archive/Web/E4X|website=Mozilla Developer Network|publisher=Mozilla Foundation|date=Feb 14, 2014|accessdate=13 July 2014}}</ref>)
 
JavaScript is a single-[[Thread (computing)|threaded]] language. The runtime processes [[Message (computer science)|messages]] from a [[Queue (abstract data type)|queue]] one at a time, and it calls a [[Subroutine|function]] associated with each new message, creating a [[call stack]] frame with the function's [[Parameter (computer programming)|arguments]] and [[local variable]]s. The call stack shrinks and grows based on the function's needs. When the call stack is empty upon function completion, JavaScript proceeds to the next message in the queue. This is called the [[event loop]], described as "run to completion" because each message is fully processed before the next message is considered. However, the language's [[Concurrency (computer science)|concurrency model]] describes the event loop as [[Asynchronous I/O|non-blocking]]: program I/O is performed using [[Event (computing)|events]] and [[Callback (computer programming)|callback functions]]. This means, for example, that JavaScript can process a mouse click while waiting for a database query to return information.<ref>{{cite web|url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop|title=Concurrency model and Event Loop|website=Mozilla Developer Network|access-date=August 28, 2015|archive-date=September 5, 2015|archive-url=https://web.archive.org/web/20150905045241/https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop|url-status=live}}</ref>
== Syntax ==
{{Main article|JavaScript syntax}}
 
The notable standalone runtimes are [[Node.js]], [[Deno (software)|Deno]], and [[Bun (software)|Bun]].
=== Simple examples ===
[[Variable (computer science)|Variables]] in JavaScript can be defined using the <tt>var</tt> keyword:<ref>{{cite web | url=https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/var | title=var – JavaScript – MDN | publisher=The [[Mozilla Developer Network]] | accessdate=22 December 2012}}</ref>
 
== Features ==
<syntaxhighlight lang="javascript">
The following features are common to all conforming ECMAScript implementations unless explicitly specified otherwise. The number of cited reserved words including keywords is 50–60 and varies depending on the implementation.
var x; // defines the variable x and assigns to it the special value "undefined" (not to be confused with an undefined value)
var y = 2; // defines the variable y and assigns to it the value 2
var z = "Hello, World!"; // defines the variable z and assigns to it a string containing "Hello, World!"
</syntaxhighlight>
 
=== Imperative and structured ===
Note the [[Comment (computer programming)|comments]] in the example above, all of which were preceded with two [[Slash (punctuation)|forward slashes]].
{{Main|Structured programming}}
 
JavaScript supports much of the [[structured programming]] syntax from [[C (computer language)|C]] (e.g., <code>if</code> statements, <code>while</code> loops, <code>switch</code> statements, <code>do while</code> loops, etc.). One partial exception is [[scope (computer science)|scoping]]: originally JavaScript only had [[function scoping]] with <code>var</code>; [[block scoping]] was added in ECMAScript 2015 with the keywords <code>let</code> and <code>[[const (computer programming)|const]]</code>. Like C, JavaScript makes a distinction between [[Expression (computer science)|expressions]] and [[Statement (computer science)|statements]]. One syntactic difference from C is [[Defensive semicolon|automatic semicolon insertion]], which allow semicolons (which terminate statements) to be omitted.<ref name="Flanagan2006">{{cite book|last=Flanagan|first=David|title=JavaScript: The Definitive Guide |url=https://books.google.com/books?id=2weL0iAfrEMC|date=August 17, 2006|publisher=[[O'Reilly Media, Inc.]]|isbn=978-0-596-55447-7|page=16|access-date=March 29, 2019|archive-date=August 1, 2020|archive-url=https://web.archive.org/web/20200801065235/https://books.google.com/books?id=2weL0iAfrEMC|url-status=live}}</ref>
There is no built-in [[Input/output|I/O]] functionality in JavaScript; the run-time environment provides that. The ECMAScript specification in edition 5.1 mentions:<ref>{{cite web | url=http://www.ecma-international.org/ecma-262/5.1/#sec-4 | title=ECMAScript Language Specification – ECMA-262 Edition 5.1|publisher=[[Ecma International]] | accessdate=22 December 2012}}</ref>
<blockquote>… indeed, there are no provisions in this specification for input of external data or output of computed results.</blockquote>
However, most runtime environments have a <tt>console</tt> object<ref>{{cite web | title=console|url=https://developer.mozilla.org/en-US/docs/DOM/console|work=Mozilla Developer Network|publisher=[[Mozilla]]|accessdate=6 April 2013}}</ref> that can be used to print output. Here is a minimalist [[Hello World program]] in '''JavaScript''':
 
=== Weakly typed ===
<syntaxhighlight lang="javascript">
{{Further|Weakly typed}}
console.log("Hello World!");
</syntaxhighlight>
 
JavaScript is [[Strong and weak typing|weakly typed]], which means certain types are implicitly cast depending on the operation used.<ref name="casting_rules">{{cite web |last=Korolev |first=Mikhail |date=2019-03-01 |title=JavaScript quirks in one image from the Internet |url=https://dev.to/mkrl/javascript-quirks-in-one-image-from-the-internet-52m7 |url-status=live |archive-url=https://web.archive.org/web/20191028204723/https://dev.to/mkrl/javascript-quirks-in-one-image-from-the-internet-52m7 |archive-date=October 28, 2019 |access-date=October 28, 2019 |website=The DEV Community |language=en}}</ref>
A simple [[Recursion (computer science)|recursive]] function:
 
* The binary <code>+</code> operator casts both operands to a string unless both operands are numbers. This is because the addition operator doubles as a concatenation operator
<syntaxhighlight lang="javascript">
* The binary <code>-</code> operator always casts both operands to a number
function factorial(n) {
* Both unary operators (<code>+</code>, <code>-</code>) always cast the operand to a number. However, <code>+</code> always casts to <code>Number</code> ([[Double-precision floating-point format|binary64]]) while <code>-</code> preserves <code>BigInt</code> ([[Arbitrary-precision arithmetic|integer]])<ref>{{cite web | url=https://github.com/tc39/proposal-bigint/blob/master/ADVANCED.md#dont-break-asmjs | title=Proposal-bigint/ADVANCED.md at master · tc39/Proposal-bigint | website=[[GitHub]] }}</ref>
if (n === 0) {
return 1; // 0! = 1
}
return n * factorial(n - 1);
}
 
Values are cast to strings like the following:<ref name="casting_rules" />
factorial(3); // returns 6
</syntaxhighlight>
 
* Strings are left as-is
An [[anonymous function]] (or lambda):
* Numbers are converted to their string representation
* Arrays have their elements cast to strings after which they are joined by commas (<code>,</code>)
* Other objects are converted to the string <code>[object Object]</code> where <code>Object</code> is the name of the constructor of the object
 
Values are cast to numbers by casting to strings and then casting the strings to numbers. These processes can be modified by defining <code>toString</code> and <code>valueOf</code> functions on the [[#Object-orientation (prototype-based)|prototype]] for string and number casting respectively.
<syntaxhighlight lang="javascript">
function counter() {
var count = 0;
return function() {
return ++count;
};
}
 
JavaScript has received criticism for the way it implements these conversions as the complexity of the rules can be mistaken for inconsistency.<ref>{{cite web |date=2012 |title=Wat |url=https://www.destroyallsoftware.com/talks/wat |url-status=live |archive-url=https://web.archive.org/web/20191028204723/https://www.destroyallsoftware.com/talks/wat |archive-date=October 28, 2019 |access-date=October 28, 2019 |website=Destroy All Software |first1=Gary |last1=Bernhardt }}</ref><ref name="casting_rules" /> For example, when adding a number to a string, the number will be cast to a string before performing concatenation, but when subtracting a number from a string, the string is cast to a number before performing subtraction.
var closure = counter();
closure(); // returns 1
closure(); // returns 2
closure(); // returns 3
</syntaxhighlight>
 
{| class="wikitable"
This example shows that, in JavaScript, [[Closure (computer programming)|function closures]] capture their non-local variables ''by reference''.
|+JavaScript type conversions
!left operand
!operator
!right operand
!result
|-
|<code>[]</code> (empty array)
|<code>+</code>
|<code>[]</code> (empty array)
|<code>""</code> (empty string)
|-
|<code>[]</code> (empty array)
|<code>+</code>
|<code>{}</code> (empty object)
|<code>"[object Object]"</code> (string)
|-
|<code>false</code> (boolean)
|<code>+</code>
|<code>[]</code> (empty array)
|<code>"false"</code> (string)
|-
|<code>"123"</code>(string)
|<code>+</code>
|<code>1</code> (number)
|<code>"1231"</code> (string)
|-
|<code>"123"</code> (string)
|<code>-</code>
|<code>1</code> (number)
|<code>122</code> (number)
|-
|<code>"123"</code> (string)
|<code>-</code>
|<code>"abc"</code> (string)
|<code>[[NaN]]</code> (number)
|}
 
Often also mentioned is <code>{} + []</code> resulting in <code>0</code> (number). This is misleading: the <code>{}</code> is interpreted as an empty code block instead of an empty object, and the empty array is cast to a number by the remaining unary <code>+</code> operator. If the expression is wrapped in parentheses - <code>({} + [])</code> – the curly brackets are interpreted as an empty object and the result of the expression is <code>"[object Object]"</code> as expected.<ref name="casting_rules" />
In JavaScript, [[Object_(computer_science)|objects]] are created in the same way as functions, this is known as a [[function object]].
 
=== Dynamic ===
Object example:
{{Main|Dynamic programming}}
<syntaxhighlight lang="javascript">
function Ball(r) {
this.radius = r; //the radius variable is local to the ball object
this.area = pi*r**2;
this.show = function(){ //objects can contain functions
drawCircle(r); //references a circle drawing function
}
}
myBall = new Ball(5); //creates a new instance of the ball object with radius 5
myBall.show(); //this instance of the ball object has the show function performed on it
</syntaxhighlight>
 
==== Typing ====
[[Variadic function]] demonstration (<tt>arguments</tt> is a special [[variable (programming)|variable]]):<ref>{{cite web | title=arguments|url=https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Functions_and_function_scope/arguments|work=Mozilla Developer Network|publisher=[[Mozilla]]|accessdate=6 April 2013}}</ref>
{{Main|Dynamic typing}}
 
JavaScript is [[dynamic typing|dynamically typed]] like most other [[scripting language]]s. A [[type system|type]] is associated with a [[value (computer science)|value]] rather than an expression. For example, a [[Variable (programming)|variable]] initially bound to a number may be reassigned to a [[string (computer science)|string]].<ref>{{cite web|url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures|title=JavaScript data types and data structures |date=February 16, 2017|website=MDN |access-date=February 24, 2017|archive-date=March 14, 2017|archive-url=https://web.archive.org/web/20170314230542/https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures|url-status=live}}</ref> JavaScript supports various ways to test the type of objects, including [[duck typing]].{{Sfn|Flanagan|2006|pp=176–178}}
<syntaxhighlight lang="javascript">
function sum() {
var x = 0;
for (var i = 0; i < arguments.length; ++i) {
x += arguments[i];
}
return x;
}
sum(1, 2); // returns 3
sum(1, 2, 3); // returns 6
</syntaxhighlight>
 
==== Run-time evaluation ====
[[Immediately-invoked function expression]]s are often used to create modules, as before ECMAScript 2015 there was no built-in construct in the language. Modules allow gathering properties and methods in a namespace and making some of them private:
{{Main|eval}}
JavaScript includes an <code>[[eval]]</code> function that can execute statements provided as strings at run-time.
 
=== Object-orientation (prototype-based) ===
<syntaxhighlight lang="javascript">
Prototypal inheritance in JavaScript is described by [[Douglas Crockford]] as:
var counter = (function () {
{{Blockquote
var i = 0; // private property
|You make prototype objects, and then ... make new instances. Objects are mutable in JavaScript, so we can augment the new instances, giving them new fields and methods. These can then act as prototypes for even newer objects. We don't need classes to make lots of similar objects... Objects inherit from objects. What could be more object oriented than that?<ref>{{cite web|last=Crockford|first=Douglas|title=Prototypal Inheritance in JavaScript|url=https://javascript.crockford.com/prototypal.html|access-date=20 August 2013|archive-date=13 August 2013|archive-url=https://web.archive.org/web/20130813163035/https://javascript.crockford.com/prototypal.html|url-status=live}}</ref>
}}
 
In JavaScript, an [[Object (computer science)|object]] is an [[associative array]], augmented with a prototype (see below); each key provides the name for an object [[Property (programming)|property]], and there are two syntactical ways to specify such a name: dot notation (<code>obj.x = 10</code>) and bracket notation (<code>obj["x"] = 10</code>). A property may be added, rebound, or deleted at run-time. Most [[property (programming)|properties]] of an object (and any property that belongs to an object's prototype inheritance chain) can be enumerated using a <code>for...in</code> loop.
return { // public methods
get: function () {
alert(i);
},
set: function (value) {
i = value;
},
increment: function () {
alert(++i);
}
};
})(); // module
 
==== Prototypes ====
counter.get(); // shows 0
{{Main|Prototype-based programming}}
counter.set(6);
counter.increment(); // shows 7
counter.increment(); // shows 8
</syntaxhighlight>
 
JavaScript uses [[prototype-based programming|prototypes]] where many other object-oriented languages use [[Class (computer science)|classes]] for [[Inheritance (object-oriented programming)|inheritance]],<ref>{{cite web|title=Inheritance and the prototype chain|url=https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Inheritance_and_the_prototype_chain|work=[[Mozilla]] Developer Network |access-date=April 6, 2013|archive-date=April 25, 2013|archive-url=https://web.archive.org/web/20130425144207/https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Inheritance_and_the_prototype_chain|url-status=live}}</ref> but it's still possible to simulate most class-based features with the prototype system.<ref>{{cite book|last=Herman|first=David|title=Effective JavaScript|year=2013|publisher=Addison-Wesley|isbn=978-0-321-81218-6|page=83 |url=https://books.google.com/books?id=Nz9iAwAAQBAJ&pg=PA83 }}</ref> Additionally, [[ECMAScript |ECMAScript version 6]] (released June 2015) introduced the keywords '''class''', '''extends''' and '''super''', which serve as syntactic sugar to abstract the underlying prototypal inheritance system with a more conventional interface. Constructors are declared by specifying a method named '''constructor''', and all classes are automatically subclasses of the base class Object, similarly to Java. <syntaxhighlight lang="javascript">
=== More advanced example ===
class Person {
This sample code displays various JavaScript features.
constructor(name) {
<!-- Don't try to standardize any styling in this example—its purpose is to showcase language syntax, not provide some standard role model. -->
this.name = name;
}
}
 
class Student extends Person {
<syntaxhighlight lang="javascript">
constructor(name, id) {
/* Finds the lowest common multiple (LCM) of two numbers */
super(name);
function LCMCalculator(x, y) { // constructor function
this.id = id;
var checkInt = function(x) { // inner function
if (x % 1 !== 0) {
throw new TypeError(x + "is not an integer"); // var a = mouseX
};
 
return x
}
this.a = checkInt(x)
// semicolons ^^^^ are optional, a newline is enough
this.b = checkInt(y);
 
}
// The prototype of object instances created by a constructor is
// that constructor's "prototype" property.
LCMCalculator.prototype = { // object literal
constructor: LCMCalculator, // when reassigning a prototype, set the constructor property appropriately
gcd: function() { // method that calculates the greatest common divisor
// Euclidean algorithm:
var a = Math.abs(this.a),
b = Math.abs(this.b),
t;
if (a < b) {
// swap variables
// t = b; b = a; a = t;
[a, b] = [b, a]; // swap using destructuring assignment (ES6)
}
while (b !== 0) {
t = b;
b = a % b;
a = t;
}
// Only need to calculate GCD once, so "redefine" this method.
// (Actually not redefinition—it's defined on the instance itself,
// so that this.gcd refers to this "redefinition" instead of LCMCalculator.prototype.gcd.
// Note that this leads to a wrong result if the LCMCalculator object members "a" and/or "b" are altered afterwards.)
// Also, 'gcd' === "gcd", this['gcd'] === this.gcd
this['gcd'] = function() {
return a;
};
return a;
},
// Object property names can be specified by strings delimited by double (") or single (') quotes.
lcm: function() {
// Variable names don't collide with object properties, e.g., |lcm| is not |this.lcm|.
// not using |this.a*this.b| to avoid FP precision issues
var lcm = this.a / this.gcd() * this.b;
// Only need to calculate lcm once, so "redefine" this method.
this.lcm = function() {
return lcm;
};
return lcm;
},
toString: function() {
return "LCMCalculator: a = " + this.a + ", b = " + this.b;
}
};
 
// Define generic output function; this implementation only works for Web browsers
function output(x) {
document.body.appendChild(document.createTextNode(x));
document.body.appendChild(document.createElement('br'));
}
 
const bob = new Student("Robert", 12345);
// Note: Array's map() and forEach() are defined in JavaScript 1.6.
console.log(bob.name); // Robert
// They are used here to demonstrate JavaScript's inherent functional nature.
</syntaxhighlight>Though the underlying object mechanism is still based on prototypes, the newer syntax is similar to other object oriented languages. Private variables are declared by prefixing the field name with a [[number sign]] (#), and [[Polymorphism (computer science)|polymorphism]] is not directly supported, although it can be emulated by manually calling different functions depending on the number and type of arguments provided.<ref name="JavaScriptNext">{{cite book |last=Ghandi |first=Raju |date=2019 |title=JavaScript Next|___location=New York City |publisher=Apress Media |pages=159–171 |isbn=978-1-4842-5394-6}}</ref>
[
[25, 55],
[21, 56],
[22, 58],
[28, 56]
].map(function(pair) { // array literal + mapping function
return new LCMCalculator(pair[0], pair[1]);
}).sort((a, b) => a.lcm() - b.lcm()) // sort with this comparative function; => is a shorthand form of a function, called "arrow function"
.forEach(printResult);
 
==== Functions as object constructors ====
function printResult(obj) {
Functions double as object constructors, along with their typical role. Prefixing a function call with ''new'' will create an instance of a prototype, inheriting properties and methods from the constructor (including properties from the <code>Object</code> prototype).<ref name="Haverbeke2024">{{Cite book |title=Eloquent JavaScript |last=Haverbeke |first=Marijn |publisher=[[No Starch Press]] |isbn=978-1-71850-411-0 |edition=4th |___location=San Francisco |publication-date=September 2024 |pages=[https://eloquentjavascript.net/Eloquent_JavaScript.pdf#section*.204 97–98] |language=en |url=https://eloquentjavascript.net/Eloquent_JavaScript.pdf |archive-url=https://web.archive.org/web/20250312193854/https://eloquentjavascript.net/Eloquent_JavaScript.pdf |archive-date=2025-03-12 |url-status=live}}</ref> ECMAScript 5 offers the <code>Object.create</code> method, allowing explicit creation of an instance without automatically inheriting from the <code>Object</code> prototype (older environments can assign the prototype to <code>null</code>).<ref>{{cite web|last=Katz|first=Yehuda|title=Understanding "Prototypes" in JavaScript|date=12 August 2011|url=https://yehudakatz.com/2011/08/12/understanding-prototypes-in-javascript/|access-date=April 6, 2013|archive-date=5 April 2013|archive-url=https://web.archive.org/web/20130405154842/https://yehudakatz.com/2011/08/12/understanding-prototypes-in-javascript/|url-status=live}}</ref> The constructor's <code>prototype</code> property determines the object used for the new object's internal prototype. New methods can be added by modifying the prototype of the function used as a constructor.<syntaxhighlight lang="javascript">// This code is completely equivalent to the previous snippet
output(obj + ", gcd = " + obj.gcd() + ", lcm = " + obj.lcm());
function Person(name) {
this.name = name;
}
</syntaxhighlight>
 
function Student(name, id) {
The following output should be displayed in the browser window.
Person.call(this, name);
<syntaxhighlight lang="html4strict">
this.id = id;
LCMCalculator: a = 28, b = 56, gcd = 28, lcm = 56
}
LCMCalculator: a = 21, b = 56, gcd = 7, lcm = 168
LCMCalculator: a = 25, b = 55, gcd = 5, lcm = 275
LCMCalculator: a = 22, b = 58, gcd = 2, lcm = 638
</syntaxhighlight>
 
var bob = new Student("Robert", 12345);
== Use in Web pages ==
console.log(bob.name); // Robert</syntaxhighlight>JavaScript's built-in classes, such as <code>Array</code> and <code>Object</code>, also have prototypes that can be modified. However, it's generally considered bad practice to [[Monkey patch|modify built-in objects]], because third-party code may use or inherit methods and properties from these objects, and may not expect the prototype to be modified.<ref>{{cite book |last=Herman |first=David |url=https://books.google.com/books?id=Nz9iAwAAQBAJ&pg=PA125 |title=Effective JavaScript |publisher=Addison-Wesley |year=2013 |isbn=978-0-321-81218-6 |pages=125–127}}</ref>
{{See also|Dynamic HTML|Ajax (programming)}}
 
==== Functions as methods ====
As of May 2017 94.5% of 10 million most popular web pages used JavaScript.<ref>{{cite web|url=https://w3techs.com/technologies/details/cp-javascript/all/all|title=Usage Statistics of JavaScript for Websites, March 2018|website=w3techs.com}}</ref> The most common use of JavaScript is to add client-side behavior to [[HTML]] pages, also known as [[Dynamic HTML]] (DHTML). Scripts are embedded in or included from [[HTML]] pages and interact with the [[Document Object Model]] (DOM) of the page. Some simple examples of this usage are:
{{Main|Method (computer science)}}
<!--not sure where to classify this under-->
 
Unlike in many object-oriented languages, in JavaScript there is no distinction between a function definition and a [[method (computer science)|method]] definition. Rather, the distinction occurs during function calling. When a function is called as a method of an object, the function's local ''this'' keyword is bound to that object for that invocation.
* Loading new page content or submitting data to the server via [[Ajax (programming)|Ajax]] without reloading the page (for example, a social network might allow the user to post status updates without leaving the page).
* Animation of page elements, fading them in and out, resizing them, moving them, etc.
* Interactive content, for example games, and playing audio and video.
* [[Data validation|Validating]] input values of a [[Form (HTML)|Web form]] to make sure that they are acceptable before being submitted to the server.
* Transmitting information about the user's reading habits and browsing activities to various websites. Web pages frequently do this for [[Web analytics]], [[ad tracking]], [[personalization]] or other purposes.
 
=== Functional ===
Because JavaScript code can run locally in a user's browser (rather than on a remote server), the browser can respond to user actions quickly, making an application more responsive. Furthermore, JavaScript code can detect user actions that HTML alone cannot, such as individual keystrokes. Applications such as [[Gmail]] take advantage of this: much of the user-interface logic is written in JavaScript, and JavaScript dispatches requests for information (such as the content of an e-mail message) to the server. The wider trend of Ajax programming similarly exploits this strength.
{{Main|Functional programming}}
 
JavaScript [[Subroutine|functions]] are [[first-class function|first-class]]; a function is considered to be an object.<ref>{{cite web|title=Function&nbsp;– JavaScript|url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function|access-date=2021-10-30|website=[[MDN Web Docs]]|language=en-US}}</ref> As such, a function may have properties and methods, such as <code>.call()</code> and <code>.bind()</code>.<ref>{{cite web | url=https://es5.github.com/#x15.3.4-toc | title=Properties of the Function Object | publisher=Es5.github.com | access-date=May 26, 2013 | archive-date=January 28, 2013 | archive-url=https://web.archive.org/web/20130128185825/https://es5.github.com/#x15.3.4-toc | url-status=live }}</ref>
A [[JavaScript engine]] (also known as JavaScript interpreter or JavaScript implementation) is an [[interpreter (computing)|interpreter]] that interprets JavaScript [[source code]] and executes the [[computer program|script]] accordingly. The first JavaScript engine was created by Brendan Eich at Netscape, for the Netscape Navigator Web browser. The engine, code-named [[SpiderMonkey (JavaScript engine)|SpiderMonkey]], is implemented in [[C (programming language)|C]]. It has since been updated (in JavaScript 1.5) to conform to ECMAScript 3. The [[Rhino (JavaScript engine)|Rhino]] engine, created primarily by Norris Boyd (formerly at Netscape, now at Google) is a JavaScript implementation in [[Java (programming language)|Java]]. Rhino, like SpiderMonkey, is ECMAScript 3 compliant.
 
==== Lexical closure ====
A Web browser is by far the most common host environment for JavaScript. Web browsers typically create "host objects" to represent the DOM in JavaScript. The [[Web server]] is another common host environment. A [[Server-side JavaScript|JavaScript Web server]] would typically expose host objects representing [[HTTP]] request and response objects, which a JavaScript program could then interrogate and manipulate to dynamically generate Web pages.
{{Main|Closure (computer programming)}}
 
A ''nested'' function is a function defined within another function. It is created each time the outer function is invoked.
Because JavaScript is the only language that the most popular browsers share support for, it has become a [[target language (computing)|target language]] for many frameworks in other languages, even though JavaScript was never intended to be such a language.<ref name="computerworld">{{cite web | last=Hamilton|first=Naomi|url=http://www.computerworld.com.au/article/255293/-z_programming_languages_javascript|title=The A-Z of Programming Languages: JavaScript|publisher=computerworld.com.au|date=2008-07-31}}</ref> Despite the performance limitations inherent to its dynamic nature, the increasing speed of JavaScript engines has made the language a surprisingly feasible compilation target.
 
In addition, each nested function forms a [[Closure (computer programming)|lexical closure]]: the [[Scope (programming)#Lexical scoping vs. dynamic scoping|lexical scope]] of the outer function (including any constant, local variable, or argument value) becomes part of the internal state of each inner function object, even after execution of the outer function concludes.{{Sfn|Flanagan|2006|p=141}}
=== Example script ===
Below is a minimal example of a standards-conforming Web page containing JavaScript (using [[HTML 5]] syntax) and the DOM:
 
==== Anonymous function ====
<syntaxhighlight lang="html5">
{{Main|Anonymous function}}
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<button id="hellobutton">Hello</button>
<script>
document.getElementById('hellobutton').onclick = function() {
alert('Hello world!'); // Show a dialog
var myTextNode = document.createTextNode('Some new words.');
document.body.appendChild(myTextNode); // Append "Some new words" to the page
};
</script>
</body>
</html>
</syntaxhighlight>
 
JavaScript also supports [[anonymous function]]s.
=== Compatibility considerations ===
{{Main article|Web interoperability}}
 
=== Delegative ===
Because JavaScript runs in widely varying environments, an important part of testing and debugging is to test and verify that the JavaScript works across multiple browsers.
{{Main|Delegation (object-oriented programming)}}
JavaScript supports implicit and explicit [[Delegation (object-oriented programming)|delegation]].
 
==== Functions as roles (Traits and Mixins) ====
The DOM interfaces for manipulating Web pages are not part of the ECMAScript standard, or of JavaScript itself. Officially, the DOM interfaces are defined by a separate standardization effort by the [[World Wide Web Consortium|W3C]]; in practice, browser implementations differ from the standards and from each other, and not all browsers execute JavaScript.
{{Main|Role-oriented programming|Traits (computer science)|Mixin}}
 
JavaScript natively supports various function-based implementations of [[Role-oriented programming|Role]]<ref>[https://peterseliger.blogspot.de/2014/04/the-many-talents-of-javascript.html#the-many-talents-of-javascript-for-generalizing-role-oriented-programming-approaches-like-traits-and-mixins The many talents of JavaScript for generalizing Role-Oriented Programming approaches like Traits and Mixins] {{Webarchive|url=https://web.archive.org/web/20171005050713/https://peterseliger.blogspot.de/2014/04/the-many-talents-of-javascript.html#the-many-talents-of-javascript-for-generalizing-role-oriented-programming-approaches-like-traits-and-mixins |date=2017-10-05 }}, Peterseliger.blogspot.de, April 11, 2014.</ref> patterns like [[Traits (computer science)|Traits]]<ref>[https://soft.vub.ac.be/~tvcutsem/traitsjs/ Traits for JavaScript] {{Webarchive|url=https://web.archive.org/web/20140724052500/https://soft.vub.ac.be/~tvcutsem/traitsjs/ |date=2014-07-24 }}, 2010.</ref><ref>{{cite web |url=https://cocktailjs.github.io/ |title=Home &#124; CocktailJS |website=Cocktailjs.github.io |access-date=February 24, 2017 |archive-date=February 4, 2017 |archive-url=https://web.archive.org/web/20170204083608/https://cocktailjs.github.io/ |url-status=live }}</ref> and [[Mixin]]s.<ref>{{cite web |url-status=live |first1=Angus |last1=Croll |url=https://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/ |title=A fresh look at JavaScript Mixins |archive-url=https://web.archive.org/web/20200415004603/https://javascriptweblog.wordpress.com/2011/05/31/a-fresh-look-at-javascript-mixins/ |archive-date=2020-04-15 |date=May 31, 2011 |website= JavaScript, JavaScript… }}</ref> Such a function defines additional behavior by at least one method bound to the <code>this</code> keyword within its <code>function</code> body. A Role then has to be delegated explicitly via <code>call</code> or <code>apply</code> to objects that need to feature additional behavior that is not shared via the prototype chain.
To deal with these differences, JavaScript authors can attempt to write standards-compliant code that will also be executed correctly by most browsers; failing that, they can write code that checks for the presence of certain browser features and behaves differently if they are not available.<ref>{{cite web|url=http://www.quirksmode.org/js/support.html |title=Javascript - Object detection |website=Quirksmode.org |date= |accessdate=2017-02-24}}</ref> In some cases, two browsers may both implement a feature but with different behavior, and authors may find it practical to detect what browser is running and change their script's behavior to match.<ref>Peter-Paul Koch, [http://www.evolt.org/node/23335 Mission Impossible – mouse position]</ref><ref>{{cite web|url=http://www.quirksmode.org/js/detect.html |title=JavaScript - Browser detect |website=Quirksmode.org |date= |accessdate=2017-02-24}}</ref> Programmers may also use libraries or toolkits that take browser differences into account.
 
==== Object composition and inheritance ====
Furthermore, scripts may not work for some users. For example, a user may:
Whereas explicit function-based delegation does cover [[Object composition|composition]] in JavaScript, implicit delegation already happens every time the prototype chain is walked in order to, e.g., find a method that might be related to but is not directly owned by an object. Once the method is found it gets called within this object's context. Thus [[Inheritance (object-oriented programming)|inheritance]] in JavaScript is covered by a delegation automatism that is bound to the prototype property of constructor functions.
 
=== Miscellaneous ===
* use an old or rare browser with incomplete or unusual DOM support;
==== Zero-based numbering ====
* use a [[Personal digital assistant|PDA]] or [[mobile phone]] browser that cannot execute JavaScript;
JavaScript is a [[Zero-based numbering#Usage in programming languages|zero-index]] language.
* have JavaScript execution disabled as a security precaution;
* use a speech browser due to, for example, a visual disability.
 
==== Variadic functions ====
To support these users, Web authors can try to create pages that [[Fault-tolerant system|degrade gracefully]] on user agents (browsers) that do not support the page's JavaScript. In particular, the page should remain usable albeit without the extra features that the JavaScript would have added. Some sites use the HTML <noscript> tag, which contains alt content if JS is disabled. An alternative approach that many find preferable is to first author content using basic technologies that work in all browsers, then enhance the content for users that have JavaScript enabled. This is known as [[progressive enhancement]].
{{Main|Variadic function}}
 
<!--note: this is not a functional programming feature-->
== Security ==
An indefinite number of parameters can be passed to a function. The function can access them through [[formal parameter]]s and also through the local <code>arguments</code> object. [[Variadic functions]] can also be created by using the <code>[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind bind]</code> method.
{{See also|Browser security}}
 
==== Array and object literals ====
JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the Web. Browser authors minimize this risk using two restrictions. First, scripts run in a [[Sandbox (computer security)|sandbox]] in which they can only perform Web-related actions, not general-purpose programming tasks like creating files. Second, scripts are constrained by the [[same-origin policy]]: scripts from one Web site do not have access to information such as usernames, passwords, or cookies sent to another site. Most JavaScript-related security bugs are breaches of either the same origin policy or the sandbox.
{{Main|Associative arrays|Object literal}}
 
Like in many scripting languages, arrays and objects ([[associative arrays]] in other languages) can each be created with a succinct shortcut syntax. In fact, these [[Object literal|literals]] form the basis of the [[JSON]] data format.
There are subsets of general JavaScript—ADsafe, Secure ECMAScript (SES)—that provide greater levels of security, especially on code created by third parties (such as advertisements).<ref>{{cite web | url=http://www.adsafe.org/ | title=Making JavaScript Safe for Advertising | publisher=ADsafe | accessdate=2013-05-26}}</ref><ref>{{cite web | url=https://code.google.com/p/es-lab/wiki/SecureEcmaScript | title=Secure ECMA Script (SES) | publisher=Code.google.com | accessdate=2013-05-26}}</ref> [[Caja project|Caja]] is another project for safe embedding and isolation of third-party JavaScript and HTML.
 
==== Regular expressions ====
[[Content Security Policy]] is the main intended method of ensuring that only trusted code is executed on a Web page.
{{Main|Regular expression}}
 
JavaScript supports [[regular expression]]s for text searches and manipulation.{{r|n=Haverbeke2024|p=139}}
{{See also|Content Security Policy}}
 
===== Cross-site vulnerabilitiesPromises =====
{{Main|Futures and promises}}
{{Main article|Cross-site scripting|Cross-site request forgery}}
 
A built-in Promise object provides functionality for handling promises and associating handlers with an asynchronous action's eventual result. JavaScript supplies combinator methods, which allow developers to combine multiple JavaScript promises and do operations based on different scenarios. The methods introduced are: Promise.race, Promise.all, Promise.allSettled and Promise.any.
A common JavaScript-related security problem is [[cross-site scripting]] (XSS), a violation of the [[same-origin policy]]. XSS vulnerabilities occur when an attacker is able to cause a target Web site, such as an online banking website, to include a malicious script in the webpage presented to a victim. The script in this example can then access the banking application with the privileges of the victim, potentially disclosing secret information or transferring money without the victim's authorization. A solution to XSS vulnerabilities is to use ''HTML escaping'' whenever displaying untrusted data.
 
===== Async/await =====
Some browsers include partial protection against ''reflected'' XSS attacks, in which the attacker provides a URL including malicious script. However, even users of those browsers are vulnerable to other XSS attacks, such as those where the malicious code is stored in a database. Only correct design of Web applications on the server side can fully prevent XSS.
{{Main|Async/await}}
 
Async/await allows an asynchronous, non-blocking function to be structured in a way similar to an ordinary synchronous function. Asynchronous, non-blocking code can be written, with minimal overhead, structured similarly to traditional synchronous, blocking code.
XSS vulnerabilities can also occur because of implementation mistakes by browser authors.<ref>{{cite web|url=http://www.mozillazine.org/talkback.html?article=4392 |title=Mozilla Cross-Site Scripting Vulnerability Reported and Fixed - MozillaZine Talkback |website=Mozillazine.org |date= |accessdate=2017-02-24}}</ref>
 
=== Vendor-specific extensions ===
Another cross-site vulnerability is [[cross-site request forgery]] (CSRF). In CSRF, code on an attacker's site tricks the victim's browser into taking actions the user didn't intend at a target site (like transferring money at a bank). It works because, if the target site relies only on cookies to authenticate requests, then requests initiated by code on the attacker's site will carry the same legitimate login credentials as requests initiated by the user. In general, the solution to CSRF is to require an authentication value in a hidden form field, and not only in the cookies, to authenticate any request that might have lasting effects. Checking the HTTP Referrer header can also help.
Historically, some [[JavaScript engine]]s supported these non-standard features:
* [[List comprehension|array comprehensions]] and generator expressions (like Python)
* concise function expressions (<code>function(args) expr</code>; this experimental syntax predated arrow functions)
* [[ECMAScript for XML]] (E4X), an extension that adds native XML support to ECMAScript (unsupported in Firefox since version 21<ref>{{cite web|title=E4X – Archive of obsolete content |url=https://developer.mozilla.org/en-US/docs/Archive/Web/E4X|website=Mozilla Developer Network|publisher=Mozilla Foundation|date=February 14, 2014|access-date=July 13, 2014|archive-date=July 24, 2014|archive-url=https://web.archive.org/web/20140724100129/https://developer.mozilla.org/en-US/docs/Archive/Web/E4X|url-status=dead}}</ref>)
 
== Syntax ==
"JavaScript hijacking" is a type of CSRF attack in which a <tt><nowiki><script></nowiki></tt> tag on an attacker's site exploits a page on the victim's site that returns private information such as [[JSON]] or JavaScript. Possible solutions include:
{{Main|JavaScript syntax}}
[[Variable (computer science)|Variables]] in JavaScript can be defined using either the <code>var</code>,<ref>{{cite web | url=https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/var | title=var – JavaScript | publisher=The [[Mozilla Developer Network]] | access-date=December 22, 2012 | archive-date=December 23, 2012 | archive-url=https://web.archive.org/web/20121223162713/https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/var | url-status=live }}</ref> <code>let</code><ref name="moz_let">{{cite web |title=let |url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let |website=MDN web docs |publisher=Mozilla |access-date=June 27, 2018 |ref=moz_let |archive-date=May 28, 2019 |archive-url=https://web.archive.org/web/20190528140803/https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let |url-status=live }}</ref> or <code>const</code><ref name="moz_const">{{cite web |title=const |url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const |website=MDN web docs |publisher=Mozilla |access-date=June 27, 2018 |ref=moz_const |archive-date=June 28, 2018 |archive-url=https://web.archive.org/web/20180628044054/https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const |url-status=live }}</ref> keywords. Variables defined without keywords will be defined at the global scope.
 
Arrow functions were first introduced in [[w:ECMAScript#6th Edition – ECMAScript 2015|6th Edition – ECMAScript 2015]]. They shorten the syntax for writing functions in JavaScript. Arrow functions are anonymous, so a variable is needed to refer to them in order to invoke them after their creation, unless surrounded by parenthesis and executed immediately.
* requiring an authentication token in the [[POST (HTTP)|POST]] and [[GET (HTTP)|GET]] parameters for any response that returns private information.
 
Here is an example of JavaScript syntax.
=== Misplaced trust in the client ===
<syntaxhighlight lang="javascript" start="1">
Developers of client-server applications must recognize that untrusted clients may be under the control of attackers. The application author cannot assume that his JavaScript code will run as intended (or at all) because any secret embedded in the code could be extracted by a determined adversary. Some implications are:
// Declares a function-scoped variable named `x`, and implicitly assigns the
* Web site authors cannot perfectly conceal how their JavaScript operates because the raw source code must be sent to the client. The code can be [[obfuscated code|obfuscated]], but obfuscation can be reverse-engineered.
// special value `undefined` to it. Variables without value are automatically
* JavaScript form validation only provides convenience for users, not security. If a site verifies that the user agreed to its terms of service, or filters invalid characters out of fields that should only contain numbers, it must do so on the server, not only the client.
// set to undefined.
* Scripts can be selectively disabled, so JavaScript can't be relied on to prevent operations such as right-clicking on an image to save it.<ref>{{cite journal
// var is generally considered bad practice and let and const are usually preferred.
|title = Right-click "protection"? Forget about it
var x;
|date = 2008-06-17
|url = http://blog.anta.net/2008/06/17/right-click-%e2%80%9cprotection%e2%80%9d-forget-about-it/
|issn = 1797-1993
|accessdate = 2008-06-17
|deadurl = yes
|archiveurl = https://www.webcitation.org/618GtbF4O?url=http://blog.anta.net/2008/06/17/right-click-%E2%80%9Cprotection%E2%80%9D-forget-about-it/
|archivedate = 2011-08-22
|df =
}}</ref>
* It is extremely bad practice to embed sensitive information such as passwords in JavaScript because it can be extracted by an attacker.
 
// Variables can be manually set to `undefined` like so
=== Misplaced trust in developers ===
let x2 = undefined;
Package management systems such as [[Npm (software)|npm]] and [[Bower (software)|Bower]] are popular with JavaScript developers. Such systems allow a developer to easily manage their program's dependencies upon other developer's program libraries. Developers trust that the maintainers of the libraries will keep them secure and up to date, but that is not always the case. A vulnerability has emerged because of this blind trust. Relied-upon libraries can have new releases that cause bugs or vulnerabilities to appear in all programs that rely upon the libraries. Inversely, a library can go unpatched with known vulnerabilities out in the wild. In a study done looking over a sample of 133k websites, researchers found 37% of the websites included a library with at-least one known vulnerability.<ref name="jslibs">{{cite journal
| title = Thou Shalt Not Depend on Me: Analysing the Use of Outdated JavaScript Libraries on the Web
| date = 2016-12-21
| url = http://www.ccs.neu.edu/home/arshad/publications/ndss2017jslibs.pdf
| accessdate = 2017-02-22 }}</ref> "The median lag between the oldest library version used on each website and the newest available version of that library is 1,177 days in ALEXA, and development of some libraries still in active use ceased years ago."<ref name="jslibs"/> Another possibility is that the maintainer of a library may remove the library entirely. This occurred in March 2016 when Azer Koçulu removed his repository from [[Npm (software)|npm]]. This caused all tens of thousands of programs and websites depending upon his libraries to break.<ref>Quartz, [https://qz.com/646467/how-one-programmer-broke-the-internet-by-deleting-a-tiny-piece-of-code/ How one programmer broke the internet by deleting a tiny piece of code]</ref><ref>SC Magazine UK, [https://www.scmagazineuk.com/developers-11-lines-of-deleted-code-breaks-the-internet/article/532050/ Developer's 11 lines of deleted code 'breaks the internet']</ref>
 
// Declares a block-scoped variable named `y`, and implicitly sets it to
=== Browser and plugin coding errors ===
// `undefined`. The `let` keyword was introduced in ECMAScript 2015.
JavaScript provides an interface to a wide range of browser capabilities, some of which may have flaws such as [[buffer overflow]]s. These flaws can allow attackers to write scripts that would run any code they wish on the user's system. This code is not by any means limited to another JavaScript application. For example, a buffer overrun exploit can allow an attacker to gain access to the operating system's [[API]] with superuser privileges.
let y;
 
// Declares a block-scoped, un-reassignable variable named `z`, and sets it to
These flaws have affected major browsers including Firefox,<ref>Mozilla Corporation, [http://www.mozilla.org/security/announce/2006/mfsa2006-38.html Buffer overflow in crypto.signText()]</ref> Internet Explorer,<ref>{{cite web|last1=Festa |first1=Paul |title=Buffer-overflow bug in IE |url=http://news.com.com/2100-1001-214620.html |archive-url=https://web.archive.org/web/20021225190522/http://news.com.com/2100-1001-214620.html |dead-url=yes |archive-date=December 25, 2002 |website=[[CNET]] |date=August 19, 1998 |accessdate= |df= }}</ref> and Safari.<ref>SecurityTracker.com, [http://securitytracker.com/alerts/2006/Mar/1015713.html Apple Safari JavaScript Buffer Overflow Lets Remote Users Execute Arbitrary Code and HTTP Redirect Bug Lets Remote Users Access Files]</ref>
// a string literal. The `const` keyword was also introduced in ECMAScript 2015,
// and must be explicitly assigned to.
 
// The keyword `const` means constant, hence the variable cannot be reassigned
Plugins, such as video players, [[Adobe Flash#Flash client security|Adobe Flash]], and the wide range of [[ActiveX]] controls enabled by default in Microsoft Internet Explorer, may also have flaws exploitable via JavaScript (such flaws have been exploited in the past).<ref>SecurityFocus, [http://www.securityfocus.com/bid/19030/info Microsoft WebViewFolderIcon ActiveX Control Buffer Overflow Vulnerability]</ref><ref>Fusion Authority, [http://www.fusionauthority.com/security/3234-macromedia-flash-activex-buffer-overflow.htm Macromedia Flash ActiveX Buffer Overflow] {{webarchive|url=https://www.webcitation.org/618GwPiuw?url=http://www.fusionauthority.com/security/3234-macromedia-flash-activex-buffer-overflow.htm |date=2011-08-22 }}</ref>
// as the value is `constant`.
const z = "this value cannot be reassigned!";
 
// Declares a global-scoped variable and assigns 3. This is generally considered
In Windows Vista, Microsoft has attempted to contain the risks of bugs such as buffer overflows by running the Internet Explorer process with limited privileges.<ref>{{cite web|author= |url=http://blogs.msdn.com/ie/archive/2006/02/09/528963.aspx |title=Protected Mode in Vista IE7 – IEBlog |website=Blogs.msdn.com |date=2006-02-09 |accessdate=2017-02-24}}</ref> [[Google Chrome]] similarly confines its page renderers to their own "sandbox".
// bad practice, and will not work if strict mode is on.
t = 3;
 
// Declares a variable named `myNumber`, and assigns a number literal (the value
=== Sandbox implementation errors ===
// `2`) to it.
Web browsers are capable of running JavaScript outside the sandbox, with the privileges necessary to, for example, create or delete files. Of course, such privileges aren't meant to be granted to code from the Web.
let myNumber = 2;
 
// Reassigns `myNumber`, setting it to a string literal (the value `"foo"`).
Incorrectly granting privileges to JavaScript from the Web has played a role in vulnerabilities in both Internet Explorer<ref>US CERT, [https://www.kb.cert.org/vuls/id/713878 Vulnerability Note VU#713878: Microsoft Internet Explorer does not properly validate source of redirected frame]</ref> and Firefox.<ref>Mozilla Foundation, [http://www.mozilla.org/security/announce/2005/mfsa2005-41.html Mozilla Foundation Security Advisory 2005–41: Privilege escalation via DOM property overrides]</ref> In Windows XP Service Pack 2, Microsoft demoted JScript's privileges in Internet Explorer.<ref>Microsoft Corporation, [https://technet.microsoft.com/en-us/library/bb457150.aspx#EHAA Changes to Functionality in Microsoft Windows XP Service Pack 2: Part 5: Enhanced Browsing Security]</ref>
// JavaScript is a dynamically-typed language, so this is legal.
myNumber = "foo";
</syntaxhighlight>
 
Note the [[Comment (computer programming)|comments]] in the examples above, all of which were preceded with two [[Slash (punctuation)|forward slashes]].
[[Microsoft Windows]] allows JavaScript source files on a computer's hard drive to be launched as general-purpose, non-sandboxed programs (see: [[Windows Script Host]]). This makes JavaScript (like [[VBScript]]) a theoretically viable vector for a [[Trojan horse (computing)|Trojan horse]], although JavaScript Trojan horses are uncommon in practice.<ref>For one example of a rare JavaScript Trojan Horse, see Symantec Corporation, [http://www.symantec.com/security_response/writeup.jsp?docid=2003-100111-0931-99 JS.Seeker.K]</ref>{{not in citation|date=March 2017}}
 
More examples can be found at the [[wikibooks:JavaScript/Syntax examples|Wikibooks page on JavaScript syntax examples]].
=== Hardware vulnerabilities ===
In 2015, a JavaScript-based proof-of-concept implementation of a [[rowhammer]] attack was described in a paper by security researchers.<ref>{{cite arxiv | eprint = 1507.06955 | title = Rowhammer.js: A Remote Software-Induced Fault Attack in JavaScript | date = 2015-07-24 | last1 = Gruss | first1 = Daniel | last2 = Maurice | first2 = Clémentine | last3 = Mangard | first3 = Stefan | class = cs.CR }}</ref><ref>{{cite news|publisher=Motherboard|title=Rowhammer.js Is the Most Ingenious Hack I've Ever Seen|first=Alix|last=Jean-Pharuns|date=2015-07-30|url=https://motherboard.vice.com/en_us/article/9akpwz/rowhammerjs-is-the-most-ingenious-hack-ive-ever-seen}}</ref><ref>{{cite news|publisher=Ars Technica|title=DRAM 'Bitflipping' exploit for attacking PCs: Just add JavaScript|first=Dan|last=Goodin|date=2015-08-04|url=https://arstechnica.com/information-technology/2015/08/dram-bitflipping-exploit-for-attacking-pcs-just-add-javascript/}}</ref><ref>{{cite web
| url = http://www.slate.com/articles/technology/bitwise/2015/07/rowhammer_security_exploit_why_a_new_security_attack_is_truly_terrifying.html
| title = Rowhammer security exploit: Why a new security attack is truly terrifying
| date = {{date|2015-07-28|mdy}} | accessdate = {{date|2015-07-29|mdy}}
| author = David Auerbach | website = slate.com
}}</ref>
 
== Security ==
In 2017, a JavaScript-based attack via browser was demonstrated that could bypass [[Address space layout randomization|ASLR]]. It's called "ASLR⊕Cache" or AnC.<ref>[https://www.vusec.net/projects/anc/ AnC] VUSec, 2017</ref><ref>[https://arstechnica.com/security/2017/02/new-aslr-busting-javascript-is-about-to-make-drive-by-exploits-much-nastier/ New ASLR-busting JavaScript is about to make drive-by exploits much nastier] Ars Technica, 2017</ref>
{{See also|Browser security}}
JavaScript and the [[Document Object Model|DOM]] provide the potential for malicious authors to deliver scripts to run on a client computer via the Web. Browser authors minimize this risk using two restrictions. First, scripts run in a [[Sandbox (computer security)|sandbox]] in which they can only perform Web-related actions, not general-purpose programming tasks like creating files. Second, scripts are constrained by the [[same-origin policy]]: scripts from one website do not have access to information such as usernames, passwords, or cookies sent to another site. Most JavaScript-related security bugs are breaches of either the same origin policy or the sandbox.
 
There are subsets of general JavaScript—ADsafe, Secure ECMAScript (SES)—that provide greater levels of security, especially on code created by third parties (such as advertisements).<ref>{{cite web | url=https://www.adsafe.org/ | title=Making JavaScript Safe for Advertising | publisher=ADsafe | access-date=2021-05-08 | archive-date=2021-07-06 | archive-url=https://web.archive.org/web/20210706153324/https://www.adsafe.org/ | url-status=live }}</ref><ref>{{cite web | url=https://code.google.com/p/es-lab/wiki/SecureEcmaScript | title=Secure ECMA Script (SES) | access-date=May 26, 2013 | archive-date=May 15, 2013 | archive-url=https://web.archive.org/web/20130515073412/https://code.google.com/p/es-lab/wiki/SecureEcmaScript | url-status=live }}</ref> Closure Toolkit is another project for safe embedding and isolation of third-party JavaScript and HTML.<ref>{{cite web|title=Google Caja Project|url=https://developers.google.com/caja/|url-status=live|website=[[Google]]|access-date=2021-07-09|archive-date=2021-01-22|archive-url=https://web.archive.org/web/20210122083321/https://developers.google.com/caja/}}</ref>
== Uses outside Web pages ==
In addition to Web browsers and servers, JavaScript interpreters are embedded in a number of tools. Each of these applications provides its own [[object model]] that provides access to the host environment. The core JavaScript language remains mostly the same in each application.
 
[[Content Security Policy]] is the main intended method of ensuring that only trusted code is executed on a Web page.
=== Embedded scripting language ===
* Google's [[Google Chrome|Chrome]] extensions, [[Opera (Web browser)|Opera]]'s extensions, Apple's [[Safari (Web browser)|Safari 5]] extensions, Apple's [[Dashboard (Mac OS)|Dashboard Widgets]], Microsoft's [[Microsoft Gadgets|Gadgets]], [[Yahoo! Widgets]], [[Google Desktop#Gadgets and plug-ins|Google Desktop Gadgets]], and [[Serence]] [[Klipfolio]] are implemented using JavaScript.
* The [[MongoDB]] database accepts queries written in JavaScript. [[MongoDB]] and [[NodeJS]] are the core components of [[MEAN (software bundle)|MEAN]]: a [[solution stack]] for creating Web applications using just JavaScript.
* The [[Clusterpoint]] database accept queries written in JS/SQL, which is a combination of [[SQL]] and JavaScript. [[Clusterpoint]] has built-in computing engine that allows execution of JavaScript code right inside the [[distributed database]].
* Adobe's [[Adobe Acrobat#Security|Acrobat and Adobe Reader]] support JavaScript in [[Portable Document Format|PDF]] files.<ref>{{cite web | url=https://www.adobe.com/devnet/acrobat/javascript.html | accessdate=2009-08-18 | title= JavaScript for Acrobat}}</ref>
* Tools in the [[Adobe Creative Suite]], including [[Adobe Photoshop|Photoshop]], [[Adobe Illustrator|Illustrator]], [[Adobe After Effects|After Effects]], [[Dreamweaver]], and [[InDesign]], allow scripting through JavaScript.
* [[OpenOffice.org]], an office application suite, as well as its popular fork [[LibreOffice]], allows JavaScript to be used as a scripting language.
* The visual programming language [[Max (software)|Max]], released by Cycling '74, offers a JavaScript model of its environment for use by developers. It allows users to reduce visual clutter by using an object for a task rather than many.
* Apple's Logic Pro X digital audio workstation (DAW) software can create custom MIDI effects plugins using JavaScript.<ref>{{cite web|url=https://www.apple.com/logic-pro/in-depth/|title=Logic Pro X|last=|first=|date=|website=Apple|publisher=Apple, Inc.|access-date=January 31, 2017}}</ref>
* The [[Unity (game engine)|Unity]] game engine supports a modified version of JavaScript for scripting via Mono.<ref>{{cite web
| url=http://unity3d.com/unity/workflow/scripting
| title=Unity Scripting
| publisher=unity3d.com
| accessdate=2013-01-29
}}</ref>
* [[DX Studio]] (3D engine) uses the [[SpiderMonkey (JavaScript engine)|SpiderMonkey]] implementation of JavaScript for game and simulation logic.<ref>{{cite web | url=http://www.dxstudio.com/features_tech.aspx
| title=Technical Specification
| publisher=dxstudio.com
| accessdate=2009-10-20
}}</ref>
* [[Maxwell Render]] ([[Rendering (computer graphics)|rendering]] software) provides an ECMA standard based scripting engine for tasks automation.<ref>THINK! The Maxwell Render Resourcer Center, [http://think.maxwellrender.com/scripting_references-269.html Scripting References]</ref>
* [[Google Apps Script]] in [[Google Spreadsheets]] and [[Google Sites]] allows users to create custom formulas, automate repetitive tasks and also interact with other Google products such as Gmail.<ref>[[Google Apps Script]], [https://www.google.com/script/start/ Google Apps Script]</ref>
* Many [[Internet Relay Chat clients|IRC clients]], like [[ChatZilla]] or [[XChat]], use JavaScript for their scripting abilities.<ref>{{cite web | title=ChatZilla! Frequently Asked Questions – 4.5. How do I write scripts?|url=http://chatzilla.hacksrus.com/faq/#scripts|publisher=Chatzilla.hacksrus.com|accessdate=11 February 2011}}</ref><ref>{{cite web|title=Xcdscript |url=http://unborn.ludost.net/xcdscript/ |accessdate=11 February 2011 |deadurl=yes |archiveurl=https://web.archive.org/web/20110501061348/http://unborn.ludost.net/xcdscript/ |archivedate= 1 May 2011 |df= }}</ref>
* [[RPG Maker]] MV uses JavaScript as its scripting language.<ref>{{cite web | url=http://www.rpgmakerweb.com/products/programs/rpg-maker-mv | accessdate=28 August 2015 | title=RPG Maker MV &#124; RPG Maker &#124; Make Your Own Games!}}</ref>
* The text editor [[UltraEdit]] uses JavaScript 1.7 as internal scripting language, introduced with version 13 in 2007.
 
=== ScriptingCross-site enginescripting ===
{{Main|Cross-site scripting}}
* Microsoft's [[Active Scripting]] technology supports [[JScript]] as a scripting language.<ref name="VersionInformation">{{cite web | url=http://msdn.microsoft.com/en-us/library/s4esdbwz(v=VS.94).aspx | title=Version Information (JavaScript) | publisher=Msdn.microsoft.com | accessdate=2013-05-26}}</ref>
* [[Java (programming language)|Java]] introduced the <tt>javax.script</tt> package in version 6 that includes a JavaScript implementation based on [[Rhino (JavaScript engine)|Mozilla Rhino]]. Thus, Java applications can host scripts that access the application's variables and objects, much like Web browsers host scripts that access a webpage's [[Document Object Model]] (DOM).<ref>{{cite web | url=http://java.sun.com/javase/6/webnotes/index.html#scripting | title=javax.script release notes | publisher=Java.sun.com | accessdate=2009-05-19}}</ref>{{Sfn|Flanagan|2006|pp=214 et seq}}
* The [[Qt (toolkit)|Qt]] C++ toolkit includes a <tt>QtScript</tt> module to interpret JavaScript, analogous to Java's <tt>javax.script</tt> package.<ref>Nokia Corporation, [http://doc.qt.nokia.com/4.6/qtscript.html QtScript Module] {{webarchive|url=https://web.archive.org/web/20100709200957/http://doc.qt.nokia.com/4.6/qtscript.html |date=2010-07-09 }}</ref>
* [[OS X Yosemite]] introduced [[JavaScript for Automation]] (JXA), which is built upon [[JavaScriptCore]] and the [[Open Scripting Architecture]]. It features an [[Objective-C]] bridge that enables entire [[Cocoa (API)|Cocoa]] applications to be programmed in JavaScript.
* Late Night Software's [[JavaScript OSA]] (also known as JavaScript for OSA, or JSOSA) is a freeware alternative to [[AppleScript]] for OS X. It is based on the Mozilla JavaScript 1.5 implementation, with the addition of a <tt>MacOS</tt> object for interaction with the operating system and third-party applications.
 
A common JavaScript-related security problem is [[cross-site scripting]] (XSS), a violation of the [[same-origin policy]]. XSS vulnerabilities occur when an attacker can cause a target Website, such as an online banking website, to include a malicious script in the webpage presented to a victim. The script in this example can then access the banking application with the privileges of the victim, potentially disclosing secret information or transferring money without the victim's authorization. One important solution to XSS vulnerabilities is [[HTML sanitization]].
=== Application platform ===
* [[ActionScript]], the programming language used in [[Adobe Flash]], is another implementation of the ECMAScript standard.
* [[Adobe AIR]] (Adobe Integrated Runtime) is a JavaScript runtime that allows developers to create desktop applications.
* [[Electron (software framework)|Electron]] is an open-source [[software framework|framework]] developed by [[GitHub]].
* [[CA Technologies]] AutoShell cross-application scripting environment is built on the [[SpiderMonkey (JavaScript engine)|SpiderMonkey]] JavaScript engine. It contains [[preprocessor]]-like extensions for command definition, as well as custom classes for various system-related tasks like file I/O, operation system command invocation and redirection, and COM scripting.
* [[Apache Cordova]] is a mobile application development framework
* [[Cocos2d]] is an open source software framework. It can be used to build games, apps and other cross platform GUI based interactive programs
* [[Chromium Embedded Framework]] (CEF) is an open source framework for embedding a [[web browser engine]] based on the [[Chromium (web browser)|Chromium]] core
* [[RhoMobile Suite]] is a set of development tools for creating data-centric, cross-platform, native mobile consumer and enterprise applications.
* [[NW.js]] call all Node.js modules directly from DOM and enable a new way of writing applications with all Web technologies.<ref>{{cite web|url=https://nwjs.io |title=NW.js |website=Nwjs.io |date= |accessdate=2017-02-24}}</ref>
* [[GNOME Shell]], the shell for the {{nobr|[[GNOME]] 3}} desktop environment,<ref>{{cite web
| url=http://gnomejournal.org/article/74/behind-the-scenes-with-owen-taylor
| title=Behind the Scenes with Owen Taylor
| publisher=The GNOME Journal
| accessdate=2010-01-23
| archiveurl=https://web.archive.org/web/20121221071408/http://gnomejournal.org/article/74/behind-the-scenes-with-owen-taylor
| archivedate=2012-12-21
}}</ref> made JavaScript its default programming language in 2013.<ref>{{cite web
| url = http://treitter.livejournal.com/14871.html
| title = Answering the question: "How do I develop an app for GNOME?"
}}</ref>
* The [[Mozilla application framework]] (XPFE) platform, which underlies [[Firefox]], [[Mozilla Thunderbird|Thunderbird]], and some other Web browsers, uses JavaScript to implement the [[graphical user interface]] (GUI) of its various products.
* [[Qt Quick]]'s markup language (available since Qt 4.7) uses JavaScript for its application logic. Its declarative syntax is also similar to JavaScript.
* [[Ubuntu Touch]] provides a JavaScript API for its unified usability interface.
* [[Open webOS]] is the next generation of web-centric platforms built to run on a wide range of form factors.<ref>{{cite web|url=http://openwebosproject.org/|title=Open webOS|date=30 March 2012|publisher=|deadurl=yes|archiveurl=https://web.archive.org/web/20120330015746/http://openwebosproject.org/|archivedate=30 March 2012|df=}}</ref>
* [[Enyo (software)|enyo JS]] is a framework to develop apps for all major platforms, from phones and tablets to PCs and TVs<ref>{{cite web|url=http://enyojs.com/ |title=Enyo JavaScript Application Framework |website=Enyojs.com |date= |accessdate=2017-02-24}}</ref>
* [[WinJS]] provides a special Windows Library for JavaScript functionality in [[Windows 8]] that enables the development of [[Metro (design language)|Modern style]] (formerly ''Metro style'') applications in [[HTML5]] and JavaScript.
* [[NativeScript]] is an open-source framework to develop apps on the Apple iOS and Android platforms.
* [[Weex]] is a framework for building Mobile cross-platform UI, created by China Tech giant [[Alibaba Group|Alibaba]]<ref>{{cite web|url=https://weex-project.io/|title=Weex|date=2 February 2017|publisher=|deadurl=bot: unknown|archiveurl=https://web.archive.org/web/20170202074333/https://weex-project.io/|archivedate=2 February 2017|df=}}</ref>
* [[XULRunner]] is packaged version of the Mozilla platform to enable standalone desktop application development
 
Some browsers include partial protection against ''reflected'' XSS attacks, in which the attacker provides a URL including malicious script. However, even users of those browsers are vulnerable to other XSS attacks, such as those where the malicious code is stored in a database. Only correct design of Web applications on the server-side can fully prevent XSS.
== Development tools ==
Within JavaScript, access to a [[debugger]] becomes invaluable when developing large, non-trivial programs. Because there can be implementation differences between the various browsers (particularly within the DOM), it is useful to have access to a debugger for each of the browsers that a Web application targets.<ref>{{cite web | url=http://www.alistapart.com/articles/advanced-debugging-with-javascript/ | title=Advanced Debugging With JavaScript | publisher=alistapart.com | date=2009-02-03 | accessdate=2010-05-28}}</ref>
 
XSS vulnerabilities can also occur because of implementation mistakes by browser authors.<ref>{{cite web |url=https://www.mozillazine.org/talkback.html?article=4392 |title=Mozilla Cross-Site Scripting Vulnerability Reported and Fixed&nbsp;– MozillaZine Talkback |website=Mozillazine.org |access-date=February 24, 2017 |archive-date=July 21, 2011 |archive-url=https://web.archive.org/web/20110721230916/http://www.mozillazine.org/talkback.html?article=4392 |url-status=live }}</ref>
Script debuggers are integrated within [[Internet Explorer]], [[Firefox]], [[Safari (Web browser)|Safari]], [[Google Chrome]], [[Opera (Web browser)|Opera]] and [[Node.js]].<ref>{{cite web | url=http://javascript.about.com/od/problemsolving/ig/JavaScript-Debugging/ | title=The JavaScript Debugging Console | publisher=javascript.about.com | date=2010-05-28 | accessdate=2010-05-28}}</ref><ref>{{cite web | url=http://www.javascript-debugger.com | title=SplineTech JavaScript Debugger – an independent standalone JavaScript Debugger | publisher=javascript-debugger.com | date=2013-08-26 | accessdate=2013-08-26}}</ref><ref>{{cite web | url=http://docs.strongloop.com/display/DOC/Debugging+with+Node+Inspector | title=Debugging with Node Inspector | publisher=docs.strongloop.com | accessdate=2014-05-07}}</ref>
 
=== Cross-site request forgery ===
In addition to the native [[Internet Explorer Developer Tools]], three debuggers are available for Internet Explorer: [[Microsoft Visual Studio]] is the richest of the three, closely followed by [[Microsoft Script Editor]] (a component of [[Microsoft Office]]),<ref>[http://msdn2.microsoft.com/en-us/library/aa202668(office.11).aspx JScript development in Microsoft Office 11] (MS InfoPath 2003)</ref> and finally the free [[Microsoft Script Debugger]] that is far more basic than the other two. The free [[Microsoft Visual Web Developer Express]] provides a limited version of the JavaScript debugging functionality in Microsoft Visual Studio. Internet Explorer has included developer tools since version 8.
{{Main|Cross-site request forgery}}
 
Another cross-site vulnerability is [[cross-site request forgery]] (CSRF). In CSRF, code on an attacker's site tricks the victim's browser into taking actions the user did not intend at a target site (like transferring money at a bank). When target sites rely solely on cookies for request authentication, requests originating from code on the attacker's site can carry the same valid login credentials of the initiating user. In general, the solution to CSRF is to require an authentication value in a hidden form field, and not only in the cookies, to authenticate any request that might have lasting effects. Checking the HTTP Referrer header can also help.
In comparison to Internet Explorer, Firefox has a more comprehensive set of developer tools, which include a debugger as well. Old versions of Firefox without these tools used a [[Firefox addon]] called [[Firebug (Firefox extension)|Firebug]], or the older [[Venkman]] debugger. Also, [[WebKit]]'s Web Inspector includes a JavaScript debugger,<ref>{{cite web | url=http://webkit.org/blog/61/introducing-drosera/ | title=Introducing Drosera – Surfin' Safari | publisher=Webkit.org | date=2006-06-28 | accessdate=2009-05-19}}</ref> which is used in [[Safari (Web browser)|Safari]]. A modified version called Blink DevTools is used in [[Google Chrome]]. [[Node.js]] has Node Inspector, an interactive debugger that integrates with the Blink DevTools, available in [[Google Chrome]]. [[Opera (Web browser)|Opera]] includes a set of tools called [[Opera Dragonfly|Dragonfly]].<ref>{{cite web | url=http://www.opera.com/dragonfly/|title=Opera DragonFly|publisher=Opera Software}}</ref>
 
"JavaScript hijacking" is a type of CSRF attack in which a {{code|<script>}} tag on an attacker's site exploits a page on the victim's site that returns private information such as [[JSON]] or JavaScript. Possible solutions include:
{{Anchor|Online dev tools}}In addition to the native computer software, there are online JavaScript IDEs, debugging aids that are themselves written in JavaScript and built to run on the Web. An example is the program [[JSLint]], developed by [[Douglas Crockford]] who has written extensively on the language. JSLint scans JavaScript code for conformance to a set of standards and guidelines. Many libraries for JavaScript, such as [[three.js]], provide links to demonstration code that can be edited by users. They are also used as a pedagogical tool by institutions such as [[Khan Academy]]<ref>{{cite web |url=http://www.khanacademy.org/cs |title=Khan Academy Computer Science|accessdate=28 Sep 2012}}</ref> to allow students to experience writing code in an environment where they can see the output of their programs, without needing any setup beyond a Web browser.
 
* requiring an authentication token in the [[POST (HTTP)|POST]] and [[GET (HTTP)|GET]] parameters for any response that returns private information.
== Benchmark tools for developers ==
Since JavaScript is getting more important for web development (frontend overtakes many aspects which were done in backend before), there is also more consideration done about performance. Especially mobile devices could have problems with rendering and processing unoptimized complex logic.
 
=== Misplaced trust in the client ===
A library for doing benchmarks is [https://benchmarkjs.com/ benchmark.js]. A benchmarking library that supports high-resolution timers and returns statistically significant results{{Citation needed|reason=Need citation on statistically significant results|date=November 2016}}.
Developers of client-server applications must recognize that untrusted clients may be under the control of attackers. The author of an application should not assume that their JavaScript code will run as intended (or at all) because any secret embedded in the code could be extracted by a determined adversary. Some implications are:
* Website authors cannot perfectly conceal how their JavaScript operates because the raw source code must be sent to the client. The code can be [[obfuscated code|obfuscated]], but obfuscation can be reverse-engineered.
* JavaScript form validation only provides convenience for users, not security. If a site verifies that the user agreed to its terms of service, or filters invalid characters out of fields that should only contain numbers, it must do so on the server, not only the client.
* Scripts can be selectively disabled, so JavaScript cannot be relied on to prevent operations such as right-clicking on an image to save it.<ref>{{cite web |last1=Kottelin |first1=Thor |title=Right-click "protection"? Forget about it |url=https://blog.anta.net/2008/06/17/right-click-%E2%80%9Cprotection%E2%80%9D-forget-about-it/ |website=blog.anta.net |access-date=28 July 2022 |archive-url=https://web.archive.org/web/20110809195359/https://blog.anta.net/2008/06/17/right-click-%E2%80%9Cprotection%E2%80%9D-forget-about-it/ |archive-date=9 August 2011 |date=17 June 2008}}</ref>
* It is considered very bad practice to embed sensitive information such as passwords in JavaScript because it can be extracted by an attacker.<ref>{{cite web |last1=Rehorik |first1=Jan |title=Why You Should Never Put Sensitive Data in Your JavaScript |url=https://www.serviceobjects.com/blog/why-you-should-never-put-sensitive-data-in-your-javascript/ |website=ServiceObjects Blog |date=29 November 2016 |publisher=ServiceObjects |access-date=June 3, 2019 |archive-date=June 3, 2019 |archive-url=https://web.archive.org/web/20190603142957/https://www.serviceobjects.com/blog/why-you-should-never-put-sensitive-data-in-your-javascript/ |url-status=live }}</ref>
* [[Prototype pollution]] is a runtime vulnerability in which attackers can overwrite arbitrary properties in an object's prototype.
 
=== Misplaced trust in developers ===
Another tool is [http://jsben.ch jsben.ch]. An online JavaScript benchmarking tool, where code snippets can be tested against each other.
Package management systems such as [[npm (software)|npm]] and Bower are popular with JavaScript developers. Such systems allow a developer to easily manage their program's dependencies upon other developers' program libraries. Developers trust that the maintainers of the libraries will keep them secure and up to date, but that is not always the case. A vulnerability has emerged because of this blind trust. Relied-upon libraries can have new releases that cause bugs or vulnerabilities to appear in all programs that rely upon the libraries. Inversely, a library can go unpatched with known vulnerabilities out in the wild. In a study done looking over a sample of 133,000 websites, researchers found 37% of the websites included a library with at least one known vulnerability.<ref name="jslibs">{{citation |last1=Lauinger |first1=Tobias |last2=Chaabane |first2=Abdelberi |last3=Arshad |first3=Sajjad |last4=Robertson |first4=William |last5=Wilson |first5=Christo |last6=Kirda |first6=Engin |title=Thou Shalt Not Depend on Me: Analysing the Use of Outdated JavaScript Libraries on the Web |url=https://www.ccs.neu.edu/home/arshad/publications/ndss2017jslibs.pdf |website=Northeastern University |access-date=28 July 2022 |archive-url=https://web.archive.org/web/20170329045344/https://www.ccs.neu.edu/home/arshad/publications/ndss2017jslibs.pdf |archive-date=29 March 2017 |doi = 10.14722/ndss.2017.23414 |date = December 21, 2016|arxiv=1811.00918 |isbn=978-1-891562-46-4 |s2cid=17885720 |url-status=dead}}</ref> "The median lag between the oldest library version used on each website and the newest available version of that library is 1,177 days in ALEXA, and development of some libraries still in active use ceased years ago."<ref name="jslibs" /> Another possibility is that the maintainer of a library may remove the library entirely. This occurred in March 2016 when Azer Koçulu removed his repository from npm. This caused tens of thousands of programs and websites depending upon his libraries to break.<ref>{{cite news |work=Quartz |url=https://qz.com/646467/how-one-programmer-broke-the-internet-by-deleting-a-tiny-piece-of-code/ |title=How one programmer broke the internet by deleting a tiny piece of code |first=Keith |last=Collins |date=March 27, 2016 |access-date=February 22, 2017 |archive-date=February 22, 2017 |archive-url=https://web.archive.org/web/20170222200836/https://qz.com/646467/how-one-programmer-broke-the-internet-by-deleting-a-tiny-piece-of-code/ |url-status=live }}</ref><ref>SC Magazine UK, [https://www.scmagazineuk.com/developers-11-lines-of-deleted-code-breaks-the-internet/article/532050/ Developer's 11 lines of deleted code 'breaks the internet'] {{Webarchive|url=https://web.archive.org/web/20170223041434/https://www.scmagazineuk.com/developers-11-lines-of-deleted-code-breaks-the-internet/article/532050/ |date=February 23, 2017 }}</ref>
 
=== Browser and plugin coding errors ===
== Version history ==
{{Further|Buffer overflow}}
{{see also|ECMAScript#Versions|ECMAScript#Version correspondence}}
JavaScript provides an interface to a wide range of browser capabilities, some of which may have flaws such as [[buffer overflow]]s. These flaws can allow attackers to write scripts that would run any code they wish on the user's system. This code is not by any means limited to another JavaScript application. For example, a buffer overrun exploit can allow an attacker to gain access to the operating system's [[API]] with superuser privileges.
JavaScript was initially developed in 1996 for use in the [[Netscape Navigator]] Web browser. In the same year Microsoft released an implementation for Internet Explorer. This implementation was called [[JScript]] due to trademark issues. In 1997, the first standardized version of the language was released under the name [[ECMAScript]] in the first edition of the ECMA-252 standard. The explicit versioning and opt-in of language features was Mozilla-specific and has been removed. Firefox 4 was the last version which referred to a JavaScript version (1.8.5). With new editions of the ECMA-262 standard, JavaScript language features are now often mentioned with their initial definition in the ECMA-262 editions.
 
These flaws have affected major browsers including Firefox,<ref>Mozilla Corporation, [https://www.mozilla.org/security/announce/2006/mfsa2006-38.html Buffer overflow in crypto.signText()] {{Webarchive|url=https://web.archive.org/web/20140604014705/https://www.mozilla.org/security/announce/2006/mfsa2006-38.html |date=2014-06-04 }}</ref> Internet Explorer,<ref>{{cite web|last1=Festa |first1=Paul |title=Buffer-overflow bug in IE |url=https://news.com.com/2100-1001-214620.html |archive-url=https://web.archive.org/web/20021225190522/https://news.com.com/2100-1001-214620.html |url-status=dead |archive-date=December 25, 2002 |website=[[CNET]] |date=August 19, 1998 }}</ref> and Safari.<ref>SecurityTracker.com, [https://securitytracker.com/alerts/2006/Mar/1015713.html Apple Safari JavaScript Buffer Overflow Lets Remote Users Execute Arbitrary Code and HTTP Redirect Bug Lets Remote Users Access Files] {{Webarchive|url=https://web.archive.org/web/20100218102849/https://securitytracker.com/alerts/2006/Mar/1015713.html |date=2010-02-18 }}</ref>
The following table is based on information from multiple sources.<ref>{{cite web | url=https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript | title=New in JavaScript |publisher=developer.mozilla.org |date=2014 | accessdate=2016-07-16}}</ref><ref>{{cite web | url=http://www.webmasterworld.com/forum91/68.htm | title=JavaScript – JScript – ECMAScript version history | publisher=Webmasterworld.com | accessdate=2009-12-17}}</ref><ref>{{cite web | author=John Resig | url=http://ejohn.org/blog/versions-of-javascript | title=Versions of JavaScript | publisher=Ejohn.org | accessdate=2009-05-19}}</ref>
 
Plugins, such as video players, [[Adobe Flash#Flash client security|Adobe Flash]], and the wide range of [[ActiveX]] controls enabled by default in Microsoft Internet Explorer, may also have flaws exploitable via JavaScript (such flaws have been exploited in the past).<ref>SecurityFocus, [https://www.securityfocus.com/bid/19030/info Microsoft WebViewFolderIcon ActiveX Control Buffer Overflow Vulnerability] {{Webarchive|url=https://web.archive.org/web/20111011091819/http://www.securityfocus.com/bid/19030/info |date=2011-10-11 }}</ref><ref>Fusion Authority, [https://www.fusionauthority.com/security/3234-macromedia-flash-activex-buffer-overflow.htm Macromedia Flash ActiveX Buffer Overflow] {{webarchive|url=https://web.archive.org/web/20110813160055/https://www.fusionauthority.com/security/3234-macromedia-flash-activex-buffer-overflow.htm |date=August 13, 2011 }}</ref>
{| class="wikitable" style="text-align:center;"
|-
! Version !! Release date !! Equivalent to !! Netscape<br />Navigator !! Mozilla<br />Firefox !! Internet<br />Explorer !! Opera !! Safari !! Google<br />Chrome
|-
| {{Version |o |1.0}} || March 1996 || || 2.0 || || 3.0 || || ||
|-
| {{Version |o |1.1}} || August 1996 || || 3.0 || || || || ||
|-
| {{Version |o |1.2}} || June 1997 || || 4.0-4.05 || || || 3 || ||
|-
| {{Version |o |1.3}} || October 1998 || ECMA-262 1st + 2nd edition || 4.06-4.7x || || 4.0 || 5<ref>{{cite web|url=http://javascript.about.com/library/bljver.htm |title=What Version of Javascript |website=Javascript.about.com |date=2016-02-22 |accessdate=2017-02-24}}</ref> || ||
|-
| {{Version |o |1.4}} || || || Netscape<br />Server || || || 6 || ||
|-
| {{Version |o |1.5}} || November 2000 || ECMA-262 3rd edition || 6.0 || 1.0 || 5.5 (JScript 5.5),<br />6 (JScript 5.6),<br />7 (JScript 5.7),<br />8 (JScript 5.8) || 7.0 || 3.0-5 || 1.0-10.0.666
|-
| {{Version |o |1.6}} || November 2005 || 1.5 + array extras + array and string generics + [[E4X]] || || 1.5 || || || ||
|-
| {{Version |o |1.7}} || October 2006 || 1.6 + [https://developer.mozilla.org/en-US/docs/JavaScript/New_in_JavaScript/1.7?redirectlocale=en-US&redirectslug=New_in_JavaScript_1.7#Generators Pythonic generators] + iterators + let || || 2.0 || || || ||28.0.1500.95
|-
| {{Version |o |1.8}} || June 2008 || 1.7 + [[generator (computer programming)|generator expressions]] + [[closure (computer programming)|expression closures]] || || 3.0 || || 11.50 || ||
|-
| {{Version |o |1.8.1}} || || 1.8 + [[JSON#Native encoding and decoding in browsers|native JSON]] support + minor updates || || 3.5 || || || ||
|-
| {{Version |o |1.8.2}} || June 22, 2009 || 1.8.1 + minor updates || || 3.6 || || || ||
|-
| {{Version |o |1.8.5}} || July 27, 2010 || 1.8.2 + new features for ECMA-262 5th edition compliance || || 4.0 || || || ||
|}
 
In Windows Vista, Microsoft has attempted to contain the risks of bugs such as buffer overflows by running the Internet Explorer process with limited privileges.<ref>{{cite web |url=https://blogs.msdn.com/ie/archive/2006/02/09/528963.aspx |title=Protected Mode in Vista IE7 – IEBlog |website=Blogs.msdn.com |date=February 9, 2006 |access-date=February 24, 2017 |archive-date=January 23, 2010 |archive-url=https://web.archive.org/web/20100123103719/https://blogs.msdn.com/ie/archive/2006/02/09/528963.aspx |url-status=live }}</ref> [[Google Chrome]] similarly confines its page renderers to their own "[[Sandbox (computer security)|sandbox]]".
== Related languages and technologies ==
[[JSON]], or JavaScript Object Notation, is a general-purpose data interchange format that is defined as a subset of JavaScript's object literal syntax. Like much of JavaScript (regexps and anonymous functions as 1st class elements, closures, flexible classes, 'use strict'), [[JSON]], except for replacing [[Perl]]'s key-value operator '=>' by an [[RFC 822]]<ref>{{cite web|url=https://tools.ietf.org/html/rfc822#section-3.2 |title=RFC 822 - STANDARD FOR THE FORMAT OF ARPA INTERNET TEXT MESSAGES |website=Tools.ietf.org |date=1982-08-13 |accessdate=2017-02-24}}</ref> inspired ':', is syntactically pure Perl.
 
=== Sandbox implementation errors ===
[[jQuery]] is a popular JavaScript library designed to simplify [[Document Object Model|DOM]]-oriented client-side HTML scripting along with offering cross-browser compatibility because various browsers respond differently to certain vanilla JavaScript code.
Web browsers are capable of running JavaScript outside the sandbox, with the privileges necessary to, for example, create or delete files. Such privileges are not intended to be granted to code from the Web.
 
Incorrectly granting privileges to JavaScript from the Web has played a role in vulnerabilities in both Internet Explorer<ref>US CERT, [https://www.kb.cert.org/vuls/id/713878 Vulnerability Note VU#713878: Microsoft Internet Explorer does not properly validate source of redirected frame] {{Webarchive|url=https://web.archive.org/web/20091030051811/https://www.kb.cert.org/vuls/id/713878/ |date=2009-10-30 }}</ref> and Firefox.<ref>Mozilla Foundation, [https://www.mozilla.org/security/announce/2005/mfsa2005-41.html Mozilla Foundation Security Advisory 2005–41: Privilege escalation via DOM property overrides] {{Webarchive|url=https://web.archive.org/web/20140604014832/https://www.mozilla.org/security/announce/2005/mfsa2005-41.html |date=2014-06-04 }}</ref> In Windows XP Service Pack 2, Microsoft demoted JScript's privileges in Internet Explorer.<ref>{{cite web |last=Andersen |first=Starr |date=2004-08-09 |url=https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb457150(v=technet.10) |title=Part 5: Enhanced Browsing Security |department=[[Microsoft TechNet|TechNet]] |website=[[Microsoft Docs]] |series=Changes to Functionality in Windows XP Service Pack 2 |access-date=2021-10-20}}</ref>
[[Underscore.js]] is a utility JavaScript library for data manipulation that is used in both client-side and server-side network applications.
 
[[Microsoft Windows]] allows JavaScript source files on a computer's hard drive to be launched as general-purpose, non-sandboxed programs (see: [[Windows Script Host]]). This makes JavaScript (like [[VBScript]]) a theoretically viable vector for a [[Trojan horse (computing)|Trojan horse]], although JavaScript Trojan horses are uncommon in practice.<ref>For one example of a rare JavaScript Trojan Horse, see Symantec Corporation, [https://www.symantec.com/security_response/writeup.jsp?docid=2003-100111-0931-99 JS.Seeker.K] {{Webarchive|url=https://web.archive.org/web/20110913210848/http://www.symantec.com/security_response/writeup.jsp?docid=2003-100111-0931-99 |date=2011-09-13 }}</ref>{{failed verification|date=March 2017}}
[[Angular (application platform)|Angular]] and [[AngularJS]] are [[web application framework]]s to use for developing [[single-page application]]s and also cross-platform mobile apps.
 
=== Hardware vulnerabilities ===
[[React (JavaScript library)]] is an [[open-source]] JavaScript library providing a views that is rendered using components specified as custom HTML tags.
In 2015, a JavaScript-based proof-of-concept implementation of a [[rowhammer]] attack was described in a paper by security researchers.<ref>{{cite arXiv | eprint = 1507.06955 | title = Rowhammer.js: A Remote Software-Induced Fault Attack in JavaScript | date = July 24, 2015 | last1 = Gruss | first1 = Daniel | last2 = Maurice | first2 = Clémentine | last3 = Mangard | first3 = Stefan | class = cs.CR }}</ref><ref>{{cite news |work=Motherboard |publisher=[[Vice (magazine)|Vice]] |title=Rowhammer.js Is the Most Ingenious Hack I've Ever Seen |first=Alix |last=Jean-Pharuns |date=July 30, 2015 |url=https://www.vice.com/en/article/rowhammerjs-is-the-most-ingenious-hack-ive-ever-seen/ |access-date=January 26, 2018 |archive-date=January 27, 2018 |archive-url=https://web.archive.org/web/20180127084042/https://motherboard.vice.com/en_us/article/9akpwz/rowhammerjs-is-the-most-ingenious-hack-ive-ever-seen |url-status=live }}</ref><ref>{{cite web|website=[[Ars Technica]]|title=DRAM 'Bitflipping' exploit for attacking PCs: Just add JavaScript|first=Dan|last=Goodin|date=August 4, 2015|url=https://arstechnica.com/information-technology/2015/08/dram-bitflipping-exploit-for-attacking-pcs-just-add-javascript/|access-date=January 26, 2018|archive-date=January 27, 2018|archive-url=https://web.archive.org/web/20180127143154/https://arstechnica.com/information-technology/2015/08/dram-bitflipping-exploit-for-attacking-pcs-just-add-javascript/|url-status=live}}</ref><ref>{{cite web | url = https://www.slate.com/articles/technology/bitwise/2015/07/rowhammer_security_exploit_why_a_new_security_attack_is_truly_terrifying.html | title = Rowhammer security exploit: Why a new security attack is truly terrifying | date = July 28, 2015 | access-date = July 29, 2015 | first = David | last = Auerbach | author-link = David Auerbach | website = slate.com | archive-date = July 30, 2015 | archive-url = https://web.archive.org/web/20150730004023/https://www.slate.com/articles/technology/bitwise/2015/07/rowhammer_security_exploit_why_a_new_security_attack_is_truly_terrifying.html | url-status = live }}</ref>
 
In 2017, a JavaScript-based attack via browser was demonstrated that could bypass [[Address space layout randomization|ASLR]]. It is called "ASLR⊕Cache" or AnC.<ref>[https://www.vusec.net/projects/anc/ AnC] {{Webarchive|url=https://web.archive.org/web/20170316055626/https://www.vusec.net/projects/anc/ |date=2017-03-16 }} VUSec, 2017</ref><ref>[https://arstechnica.com/security/2017/02/new-aslr-busting-javascript-is-about-to-make-drive-by-exploits-much-nastier/ New ASLR-busting JavaScript is about to make drive-by exploits much nastier] {{Webarchive|url=https://web.archive.org/web/20170316024419/https://arstechnica.com/security/2017/02/new-aslr-busting-javascript-is-about-to-make-drive-by-exploits-much-nastier/ |date=2017-03-16 }} Ars Technica, 2017</ref>
Mozilla browsers currently support [[LiveConnect]], a feature that allows JavaScript and Java to intercommunicate on the Web. However, Mozilla-specific support for LiveConnect was scheduled to be phased out in the future in favor of passing on the LiveConnect handling via [[NPAPI]] to the Java 1.6+ plug-in (not yet supported on the Mac {{as of|March 2010|lc=y}}).<ref>[http://java.sun.com/javase/6/webnotes/6u10/plugin2/liveconnect/ Release Notes for the Next-Generation Java™ Plug-In Technology (introduced in Java SE 6 update 10)]. Java.sun.com. Retrieved on 2013-06-13.</ref> Most browser inspection tools, such as [[Firebug (software)|Firebug]] in Firefox, include JavaScript interpreters that can act on the visible page's DOM.
 
In 2018, the paper that announced the [[Spectre (security vulnerability)|Spectre]] attacks against Speculative Execution in Intel and other processors included a JavaScript implementation.<ref>[https://spectreattack.com/spectre.pdf Spectre Attack] {{Webarchive|url=https://web.archive.org/web/20180103225843/https://spectreattack.com/spectre.pdf |date=2018-01-03 }} Spectre Attack</ref>
[[asm.js]] is a subset of JavaScript that can be run in any JavaScript engine or run faster in an [[ahead-of-time]] (AOT) compiling engine.<ref>{{cite web | url=http://asmjs.org/faq.html | title=frequently asked questions | publisher=asm.js | accessdate=2014-04-13}}</ref>
 
== Development tools ==
[[JSFuck]] is an [[esoteric programming language]]. Programs are written using only six different characters, but are still valid JavaScript code.
Important tools have evolved with the language.
 
* Every major web browser has built-in [[web development tools]], including a JavaScript [[debugger]].
[[Processing (programming language)#p5.js|p5.js]]<ref>{{cite web|url=http://p5js.org/ |title=Home |website=p5.js |date=2017-01-21 |accessdate=2017-02-24}}</ref> is an object oriented JavaScript library designed for artists and designers. It is based on the ideas of the [[Processing (programming language)|Processing]] project but is for the web.
* [[Static program analysis]] tools, such as [[ESLint]] and [[JSLint]], scan JavaScript code for conformance to a set of standards and guidelines.
* Some browsers have built-in [[Profiling (computer programming)|profilers]]. Stand-alone profiling libraries have also been created, such as benchmark.js and jsbench.<ref>{{cite web|url=https://benchmarkjs.com/|title=Benchmark.js|website=benchmarkjs.com|access-date=2016-11-06|archive-date=2016-12-19|archive-url=https://web.archive.org/web/20161219182724/https://benchmarkjs.com/|url-status=live}}</ref><ref name="auto1">{{cite web|url=https://jsben.ch|title=JSBEN.CH Performance Benchmarking Playground for JavaScript|last=JSBEN.CH|website=jsben.ch|access-date=2021-08-13|archive-date=2021-02-27|archive-url=https://web.archive.org/web/20210227052409/https://jsben.ch/|url-status=live}}</ref>
* Many [[text editor]]s have syntax highlighting support for JavaScript code.
 
== Related technologies ==
[http://jsben.ch jsben.ch] is an online JavaScript benchmarking tool, where different code snippets can be tested against each other.
=== Java ===
A common misconception is that JavaScript is directly related to [[Java (programming language)|Java]].<!-- While one is intentionally similar to the other, they're different. (Previously the misconception sentence said "JavaScript is similar to Java" but that's not a misconception) --> Both indeed have a C-like syntax (the C language being their most immediate common ancestor language). They are also typically [[Sandbox (computer security)|sandboxed]], and JavaScript was designed with Java's syntax and standard library in mind. In particular, all Java keywords were reserved in original JavaScript, JavaScript's standard library follows Java's naming conventions, and JavaScript's {{code|lang=javascript|code=Math}} and {{code|lang=javascript|code=Date}} objects are based on classes from Java 1.0.<ref name="popularity">{{cite web | url=https://brendaneich.com/2008/04/popularity/ | title=Popularity | first=Brendan | last=Eich | author-link=Brendan Eich | date=April 3, 2008 | access-date=January 19, 2012 | archive-date=July 3, 2011 | archive-url=https://web.archive.org/web/20110703020955/https://brendaneich.com/2008/04/popularity/ | url-status=live }}</ref>
 
Both languages first appeared in 1995, but Java was developed by [[James Gosling]] of Sun Microsystems and JavaScript by [[Brendan Eich]] of Netscape Communications.
[http://dspace.thapar.edu:8080/jspui/handle/10266/4162 CRISP: A Strategy guiding Cloud Application Development for Beginners] is a strategy proposed by Ayush Sahu to develop optimized and secure JavaScript application to be used in mobiles, PC's and other devices. CRISP (Conversion, Reformat code, Isolate module, Sandbox, Partition) strategy has been proposed for refined conversion of native application to JavaScript for cloud application development. JavaScript is chosen as medium for writing application because it is mostly used language among developers and provides rich API (Application Programming Interface) for writing applications.<ref>{{cite web|url=http://dspace.thapar.edu:8080/jspui/handle/10266/4162 |title=Home |website=dspace.thapar.edu:8080 |date=2016-08-26 |accessdate=2016-08-26}}</ref>
 
The differences between the two languages are more prominent than their similarities. Java has [[static typing]], while JavaScript's typing is [[Dynamic typing|dynamic]]. Java is loaded from [[Compiler|compiled]] bytecode, while JavaScript is loaded as human-readable source code. Java's objects are [[Class-based programming|class-based]], while JavaScript's are [[Prototype-based programming|prototype-based]]. Finally, Java did not support functional programming until Java 8, while JavaScript has done so from the beginning, being influenced by [[Scheme (programming language)|Scheme]].
=== Use as an intermediate language ===
As JavaScript is the most widely supported client-side language that can run within a Web browser, it has become an [[intermediate language]] for other languages to target. This has included both newly created languages and ports of existing languages. Some of these include:
* OberonScript, a full implementation of the [[Oberon (programming language)|Oberon]] programming language that compiles to high-level JavaScript.<ref>{{cite web | author=Ralph Sommerer | url=http://research.microsoft.com/apps/pubs/default.aspx?id=70288 | title=Oberon Script. A Lightweight Compiler and Runtime System for the Web | publisher=research.microsoft.com | accessdate=2015-12-18}}</ref>
* [[Objective-J]], a superset of JavaScript that compiles to standard JavaScript. It adds traditional inheritance and [[Smalltalk]]/[[Objective-C]] style dynamic dispatch and optional pseudo-static typing to JavaScript.
* [[Processing.js]], a JavaScript port of the Processing programming language designed to write visualizations, images, and interactive content. It allows Web browsers to display animations, visual applications, games and other graphical rich content without the need for a Java applet or Flash plugin.
* [[CoffeeScript]], an alternate syntax for JavaScript intended to be more concise and readable. It adds features like array comprehensions (also available in JavaScript since version 1.7)<ref>{{cite web | url=https://developer.mozilla.org/en/New_in_JavaScript_1.7#Array_comprehensions_%28Merge_into_Array_comprehensions%29 | title=New in JavaScript 1.7 | publisher=Developer.mozilla.org | date=2012-12-05 | accessdate=2013-05-26}}</ref> and pattern matching. Like Objective-J, it compiles to JavaScript. Ruby and Python have been cited as influential on CoffeeScript syntax.
* [[Google Web Toolkit]] translates a subset of Java to JavaScript.
* [[Scala (programming language)|Scala]], an object-oriented and functional programming language, has a Scala-to-JavaScript compiler.<ref>{{cite web | author=Sébastien Doeraene | url=http://lampwww.epfl.ch/~doeraene/scala-js/ | title=Scala.js | publisher=Lampwww.epfl.ch | accessdate=2014-04-13}}</ref>
* [[Pyjs]], a port of [[Google Web Toolkit]] to [[Python (programming language)|Python]] translates a subset of Python to JavaScript.
* [[Dart (programming language)|Google Dart]], an all-purpose, [[Open-source software|open source]] language that compiles to JavaScript.
* Whalesong,<ref>{{cite web | url=http://hashcollision.org/whalesong/ | title=Whalesong: a Racket to JavaScript compiler | publisher=Hashcollision.org | accessdate=2014-04-13}}</ref> a [[Racket (programming language)|Racket]]-to-JavaScript compiler.
* [[Emscripten]], a [[LLVM]]-backend for porting native libraries to JavaScript, known as [[asm.js]]<ref>{{cite web |url=http://www.webpronews.com/easily-port-c-to-html5javascript-with-emscripten-2012-04 |title=Easily Port C++ To HTML5/JavaScript With Emscripten |last=Walton |first=Zach |date=2012-04-04 |work=WebProNews |publisher=iEntry Network}}</ref>
* [[Fantom (programming language)|Fantom]] a programming language that runs on JVM, .NET and JavaScript.
* [[TypeScript]], a free and open-source programming language developed by Microsoft. It is a superset of JavaScript, and essentially adds support for optional [[type annotation]]s and some other language extensions such as classes, interfaces and modules. A TS-script compiles into plain JavaScript and can be executed in any JS host supporting [[ECMAScript]] 3 or higher. The compiler is itself written in TypeScript.
* [[Elm (programming language)]] is a pure functional language for web apps. Unlike handwritten JavaScript, Elm-generated JavaScript has zero runtime exceptions, a time-traveling debugger, and enforced semantic versioning.
* [[Haxe]], an open-source high-level multiplatform programming language and compiler that can produce applications and source code for many different platforms including JavaScript.
* ClojureScript,<ref>{{cite web | url=https://github.com/clojure/clojurescript | title=clojure/clojurescript · GitHub | publisher=Github.com | accessdate=2014-04-13}}</ref> a compiler for [[Clojure]] that targets JavaScript. It is designed to emit JavaScript code that is compatible with the advanced compilation mode of the Google Closure optimizing compiler.
* [https://bertfreudenberg.github.io/SqueakJS/ SqueakJS], a virtual machine and DOM environment for the open-source [[Squeak]] implementation of the [[Smalltalk]] programming language.
* [[Free Pascal]],<ref>{{cite web | url=http://wiki.freepascal.org/pas2js | title=pascal/pas2js · FreePascal | publisher=freepascal.org | accessdate=2017-12-24}}</ref> a compiler for [[Pascal (programming language)|Pascal]] that targets JavaScript.
 
=== JSON ===
[[JSON]] is a data format derived from JavaScript; hence the name JavaScript Object Notation. It is a widely used format supported by many other programming languages.
 
=== Transpilers ===
As JavaScript has unusual limitations – such as no explicit integer type, only double-precision binary floating point – languages<!--such as Scala--> that compile to JavaScript and do not take care to use the integer-converting shift and bitwise logical operators may have slightly different behavior than in other environments.
Many websites are JavaScript-heavy, so [[transpiler]]s have been created to convert code written in other languages, which can aid the development process.<ref name="transpilers">{{cite web |title=List of languages that compile to JS |first=Jeremy |last=Ashkenas |website=[[GitHub]] |author-link=Jeremy Ashkenas |url=https://github.com/jashkenas/coffeescript/wiki/List-of-languages-that-compile-to-JS |access-date=February 6, 2020 |archive-date=January 31, 2020 |archive-url=https://web.archive.org/web/20200131233044/https://github.com/jashkenas/coffeescript/wiki/List-of-languages-that-compile-to-JS |url-status=live }}</ref>
 
[[TypeScript]] and [[CoffeeScript]] are two notable languages that transpile to JavaScript.
=== JavaScript and Java ===
A common misconception is that JavaScript is similar or closely related to [[Java (programming language)|Java]]. It is true that both have a C-like syntax (the C language being their most immediate common ancestor language). They also are both typically [[Sandbox (computer security)|sandboxed]] (when used inside a browser), and JavaScript was designed with Java's syntax and standard library in mind. In particular, all Java keywords were reserved in original JavaScript, JavaScript's standard library follows Java's naming conventions, and JavaScript's {{code|lang=javascript|code=Math}} and {{code|lang=javascript|code=Date}} objects are based on classes from Java 1.0,<ref name="popularity">{{cite web | url=http://brendaneich.com/2008/04/popularity/ | title=Popularity | author=Brendan Eich | date=3 April 2008 | accessdate=2012-01-19}}</ref> but the similarities end there.
 
=== WebAssembly ===
[[Java (programming language)|Java]] and JavaScript both first appeared in 1995, but Java was developed by [[James Gosling]] of Sun Microsystems, and JavaScript by Brendan Eich of NetScape Communications.
[[WebAssembly]] is a newer language with a [[bytecode]] format designed to complement JavaScript, especially the performance-critical portions of [[web page]] scripts. All of the major [[JavaScript engine]]s support WebAssembly,<ref>{{cite web|url=https://visualstudiomagazine.com/articles/2017/11/06/edge-webassembly.aspx|title=Edge Browser Switches WebAssembly to 'On' -- Visual Studio Magazine|website=Visual Studio Magazine|access-date=2018-02-09|archive-date=2018-02-10|archive-url=https://web.archive.org/web/20180210002432/https://visualstudiomagazine.com/articles/2017/11/06/edge-webassembly.aspx|url-status=live}}</ref> which runs in the same [[Sandbox (computer security)|sandbox]] as regular JavaScript code.
 
[[asm.js]] is a subset of JavaScript that served as the forerunner of WebAssembly.<ref>{{cite web | url=https://asmjs.org/faq.html | title=frequently asked questions | publisher=asm.js | access-date=April 13, 2014 | archive-date=June 4, 2014 | archive-url=https://web.archive.org/web/20140604012024/https://asmjs.org/faq.html | url-status=live }}</ref>
The differences between the two languages are more prominent than their similarities. Java has [[static typing]], while JavaScript's typing is [[Dynamic typing|dynamic]]. Java is loaded from compiled bytecode, while JavaScript is loaded as human-readable source code. Java's objects are [[Class-based programming|class-based]], while JavaScript's are [[Prototype-based programming|prototype-based]]. Finally, Java did not support [[functional programming]] until Java 8, while JavaScript has done so from the beginning, being influenced by [[Scheme (programming language)|Scheme]].
 
===WebAssembly= Notes ==
{{notelist}}
 
Starting in 2017, web browsers began supporting [[WebAssembly]], a technology standardized by the [[World Wide Web Consortium|W3C]]. The WebAssembly standard specifies a binary format, which can be produced by a compiler toolchain such as [[LLVM]], to execute in the browser at near native speed. WebAssembly allows programming languages such as C, C++, C# and Java to be used as well as JavaScript to author client-side code for the World Wide Web.<ref>{{cite web|url=https://visualstudiomagazine.com/articles/2017/11/06/edge-webassembly.aspx|title=Edge Browser Switches WebAssembly to 'On' -- Visual Studio Magazine|website=Visual Studio Magazine}}</ref>
 
== See also ==
{{Portal|Computer programming}}
* [[WebAssembly]]
 
== References ==
{{Reflist|30em}}
 
== Further reading ==
{{See also|ECMAScript#External_links|l1=ECMAScript Specification Documents}}
{{Refbegin|30em}}
* {{cite book | last=Bhangal Flanagan| first=Sham David| author2=Jankowski, Tomasz | title=Foundation Web DesignJavaScript: EssentialThe HTML, JavaScript, CSS, PhotoShop, Fireworks, and FlashDefinitive Guide| yearedition=20037th|___location=Sebastopol, California| publisher=APress L. P. O'Reilly|year=2020| isbn=978-1-59059491-15295202-63}}
* {{Cite book |title=Eloquent JavaScript |last=Haverbeke |first=Marijn |publisher=[[No Starch Press]] |isbn=978-1-71850-411-0 |edition=4th |___location=San Francisco |publication-date=2024 |url=https://eloquentjavascript.net/Eloquent_JavaScript.pdf |archive-url=https://web.archive.org/web/20250312193854/https://eloquentjavascript.net/Eloquent_JavaScript.pdf |archive-date=2025-03-12 |url-status=live}}
* {{cite book | last=Burns | first=Joe | author2=Growney, Andree S. | title=JavaScript Goodies | year=2001 | publisher=Pearson Education | isbn=0-7897-2612-2}}
* {{cite book | last=Duffy Zakas| first=Scott Nicholas| title=HowPrinciples toof do Everything withObject-Oriented JavaScript | yearedition=2003 1st| publisher=OsborneNo Starch Press|year=2014| isbn=0978-07-222887-3 1593275402}}
* {{cite book |last1=Flanagan | first1= David | title= JavaScript: The Definitive Guide | edition= 5th | year= 2006 | publisher= [[O'Reilly Media|O'Reilly & Associates]] | isbn= 0-596-10199-6 | ref= harv}}
* {{cite book |last1=Flanagan | first1= David | title= JavaScript: The Definitive Guide | edition= 6th | year= 2011 | publisher= [[O'Reilly Media|O'Reilly & Associates]] | isbn= 978-0-596-80552-4 | ref= harv}}
* {{cite book | last=Goodman | first=Danny | author2=Eich, Brendan | title=JavaScript Bible | year=2001 | publisher=John Wiley & Sons | isbn=0-7645-3342-8}}
* {{cite book | last=Goodman | first=Danny | author2=Markel, Scott | title=JavaScript and DHTML Cookbook | year=2003 | publisher=O'Reilly & Associates | isbn=0-596-00467-2}}
* {{cite book | last=Harris | first=Andy | title=JavaScript Programming for the Absolute Beginner | year=2001 | publisher=Premier Press | isbn=0-7615-3410-5}}
* {{cite book | last=Haverbeke | first=Marijn | title=Eloquent JavaScript | year=2011 | publisher=No Starch Press|isbn=978-1-59327-282-1}}
* {{cite book | last=Heinle | first=Nick | author2=Koman, Richard | title=Designing with JavaScript | year=1997 | publisher=O'Reilly & Associates | isbn=1-56592-300-6}}
* {{cite book | last=Husted | first=Robert | last2=Kuslich | first2=JJ | title=Server-Side JavaScript: Developing Integrated Web Applications | edition=1st | year=1999| publisher=Addison-Wesley | isbn=0-201-43329-X}}
* {{cite book | last=McDuffie | first=Tina Spain | title=JavaScript Concepts & Techniques: Programming Interactive Web Sites | year=2003 | publisher=Franklin, Beedle & Associates | isbn=1-887902-69-4}}
* {{cite book | last=McFarlane | first=Nigel | title=Rapid Application Development with Mozilla | year=2003 | publisher=Prentice Hall Professional Technical References | isbn=0-13-142343-6}}
* {{cite book | last=Powell | first=Thomas A. | author2=Schneider, Fritz | title=JavaScript: The Complete Reference | year=2001 | publisher=McGraw-Hill Companies | isbn=0-07-219127-9}}
* {{cite book | last=Shelly | first=Gary B. | author2=Cashman, Thomas J. | author3=Dorin, William J. | author4= Quasney, Jeffrey J. | title=JavaScript: Complete Concepts and Techniques | year=2000 | publisher=Course Technology | ___location=Cambridge | isbn=0-7895-6233-2}}
* {{cite book | last=Vander Veer | first=Emily A. | title=JavaScript For Dummies | edition=4th | year=2004 | publisher=Wiley Pub. | isbn=0-7645-7659-3}}
* {{cite book | last=Watt | first=Andrew H. | author2=Watt, Jonathan A. | author3=Simon, Jinjer L. | title=Teach Yourself JavaScript in 21 Days | year=2002 | publisher=Pearson Education | isbn=0-672-32297-8}}
* {{cite book|last1= Zakas | first1= Nicholas C. | title= Professional JavaScript for Web Developers | edition= 3rd | year= 2012 | publisher= Wrox | isbn= 978-1-118-02669-4 }}
{{Refend}}
 
== External links ==
{{sisterlinksSister project links|commons=Category:JavaScript|n=no|v=Topic:JavaScript|q=no|s=no|m=no|voy=no|species=no|mw=JavaScript}}
{{Spoken Wikipedia|En-JavaScript.ogg|2013-08-date=August 20, 2013}}
* [https://javascript.info/ The Modern JavaScript Tutorial]. A community maintained continuously updated collection of tutorials on the entirety of the language.
* [[Douglas Crockford]]'s [https://www.youtube.com/playlist?list=PL62E185BB8577B63D video lectures on JavaScript]
* {{cite web |url=https://www.pldi21.org/prerecorded_hopl.12.html |title=JavaScript: The First 20 Years |access-date=2022-02-06}}
* Douglas Crockford's [http://javascript.crockford.com/survey.html A Survey of the JavaScript Programming Language]
* {{DMOZ|Computers/Programming/Languages/JavaScript/}}
* [https://github.com/jashkenas/coffee-script/wiki/List-of-languages-that-compile-to-JS/ List of languages that compile to JS]
 
{{JavaScript}}
{{Programming languages}}
{{ECMAScript}}
{{Web browsers|fsp}}
{{NodeJs}}
{{Programming languages}}
{{Portal bar|Computer programming}}
{{Authority control}}
 
Line 750 ⟶ 500:
[[Category:Functional languages]]
[[Category:Object-based programming languages]]
[[Category:High-level programming languages]]
[[Category:Programming languages created in 1995]]
[[Category:Programming languages with an ISO standard]]
Line 755 ⟶ 506:
[[Category:Scripting languages]]
[[Category:Web programming]]
[[Category:Programming languages]]