JavaScript | Wikipedia audio article

JavaScript (), often abbreviated as JS, is a high-level, interpreted scripting language that conforms to the ECMAScript specification JavaScript has curly-bracket syntax, dynamic typing, prototype-based object-orientation, and first-class functions Alongside HTML and CSS, JavaScript is one of the core technologies of the World Wide Web JavaScript enables interactive web pages and is an essential part of web applications The vast majority of websites use it, and major web browsers have a dedicated JavaScript engine to execute it As a multi-paradigm language, JavaScript supports event-driven, functional, and imperative (including object-oriented and prototype-based) programming styles It has APIs for working with text, arrays, dates, regular expressions, and the DOM, but the language itself does not include any I/O, such as networking, storage, or graphics facilities It relies upon the host environment in which it is embedded to provide these features 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 PDF software, and in runtime environments that make JavaScript available for writing mobile and desktop applications, including desktop widgets 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.Although there are similarities between JavaScript and Java, including language name, syntax, and respective standard libraries, the two languages are distinct and differ greatly in design JavaScript was influenced by programming languages such as Self and Scheme The JSON serialization format, used to store data structures in files or transmit them across networks, is based on JavaScript == History == === Beginnings at Netscape === In 1993, the National Center for Supercomputing Applications (NCSA), a unit of the University of Illinois at Urbana-Champaign, released NCSA Mosaic, the first popular graphical Web browser, which played an important part in expanding the growth of the nascent World Wide Web beyond the NeXTSTEP niche where the WorldWideWeb had formed three years earlier In 1994, a company called Mosaic Communications was founded in Mountain View, California and employed many of the original NCSA Mosaic authors to create Mosaic Netscape However, it intentionally shared no code with NCSA Mosaic The internal codename for the company’s browser was Mozilla, a portmanteau of “Mosaic and Godzilla” 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 web browser for 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 into its Netscape Navigator Before he could get started, Netscape Communications collaborated with Sun Microsystems to include Sun’s more static programming language, Java, in Netscape Navigator so as to compete with Microsoft for user adoption of Web technologies and platforms 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, 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 when it was deployed in the Netscape Navigator 2.0 beta 3 in December 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 as a marketing ploy by Netscape to give JavaScript the cachet of what was then the hot new Web programming language There is a common misconception that JavaScript was influenced by an earlier Web page scripting language developed by Nombas named Cmm (not to be confused with the later C– created in 1997) Brendan Eich, however, had never heard of Cmm before he created LiveScript 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 Nombas later switched to offering JavaScript instead of Cmm in their ScriptEase product and was part of the TC39 group that standardized ECMAScript === 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.Since 1996, the IIS web-server has supported Microsoft’s implementation of server-side Javascript—JScript—in ASP and .NET pages.Since the mid-2000s, additional server-side JavaScript implementations have been introduced, such as Node.js in 2009 === Adoption by Microsoft === 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 from that found in Netscape Navigator at the time 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 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 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 Models remained and were obstacles to widespread take-up of JavaScript on the Web === 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 were other well-known implementations of ECMAScript The release of ECMAScript 2 in June 1998 continued the standards process cycle, conforming some modifications to the ISO/IEC 16262 international standard ECMAScript 3 was released in December 1999 and is the modern-day baseline for JavaScript The original ECMAScript 4 work led by Waldemar Horwat (then at Netscape, now at Google) started in 2000 Microsoft initially participated and implemented some proposals in their JScript .NET language Over time it was clear 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 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) 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, 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 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.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, 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, jQuery, Dojo Toolkit, MooTools, and others being released 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 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 === Later developments === JavaScript has become one of the most popular programming languages on the Web However, many professional programmers initially denigrated the language due to the perceived target audience of Web authors and other such “amateurs” The advent of Ajax returned JavaScript to the spotlight and brought more professional programming attention The result was a proliferation of comprehensive 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 January 2009, the CommonJS project was founded with the goal of specifying a common standard library mainly for JavaScript development outside the browser.With the rise of single-page applications and JavaScript-heavy sites, it is increasingly being used as a compile target for source-to-source compilers from both dynamic languages and static languages == Trademark == “JavaScript” is a trademark of Oracle Corporation in the United States It is used under license for technology invented and implemented by Netscape Communications and current entities such as the Mozilla Foundation == Features == The following features are common to all conforming ECMAScript implementations, unless explicitly specified otherwise

=== Universal support === All popular modern Web browsers support JavaScript with built-in interpreters === Imperative and structured === JavaScript supports much of the structured programming syntax from C (e.g., if statements, while loops, switch statements, do while loops, etc.) One partial exception is scoping: JavaScript originally had only function scoping with var ECMAScript 2015 added keywords let and const for block scoping, meaning JavaScript now has both function and block scoping Like C, JavaScript makes a distinction between expressions and statements One syntactic difference from C is automatic semicolon insertion, which allows the semicolons that would normally terminate statements to be omitted === Dynamic === Typing JavaScript is dynamically typed like most other scripting languages A type is associated with a value rather than an expression For example, a variable initially bound to a number may be reassigned to a string JavaScript supports various ways to test the type of objects, including duck typing Run-time evaluation JavaScript includes an eval function that can execute statements provided as strings at run-time === Prototype-based (object-oriented) === JavaScript is almost entirely object-based In JavaScript, an 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 (obj.x = 10) and bracket notation (obj[‘x’] = 10) 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 for…in loop JavaScript has a small number of built-in objects, including Function and Date Prototypes JavaScript uses prototypes where many other object-oriented languages use classes for inheritance It is possible to simulate many class-based features with prototypes in JavaScript 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 Object prototype) ECMAScript 5 offers the Object.create method, allowing explicit creation of an instance without automatically inheriting from the Object prototype (older environments can assign the prototype to null) The constructor’s prototype 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 Array or Object, also have prototypes that can be modified While it is possible to modify the Object prototype, it is generally considered bad practice because most objects in JavaScript will inherit methods and properties from the Object prototype, and they may not expect the prototype to be modified Functions as methods Unlike many object-oriented languages, there is no distinction between a function definition and a 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 === Functional === A function is first-class; a function is considered to be an object As such, a function may have properties and methods, such as .call() and .bind() 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 lexical closure: The 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 JavaScript also supports anonymous functions === Delegative === JavaScript supports implicit and explicit delegation Functions as roles (Traits and Mixins) JavaScript natively supports various function-based implementations of Role patterns like Traits and Mixins Such a function defines additional behavior by at least one method bound to the this keyword within its function body A Role then has to be delegated explicitly via call or apply to objects that need to feature additional behavior that is not shared via the prototype chain Object composition and inheritance Whereas explicit function-based delegation does cover 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 in JavaScript is covered by a delegation automatism that is bound to the prototype property of constructor functions === 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 DOM) It also relies on the run-time environment to provide the ability to include/import scripts (e.g., HTML