HOME
The Info List - JavaScript



--- Advertisement ---


(i) (i)

com.netscape.javascript-source

TYPE OF FORMAT Scripting language

Part of a series on

JAVASCRIPT

* JavaScript syntax * JavaScript library * Unobtrusive JavaScript * JavaScript engine
JavaScript engine

LISTS OF FRAMEWORKS AND LIBRARIES

* Ajax frameworks * JavaScript
JavaScript
web frameworks * Comparison of JavaScript frameworks * List of JavaScript libraries * JavaScript
JavaScript
unit testing frameworks

JAVASCRIPT OBJECT NOTATION

_See also_

* ECMAScript

* v * t * e

JAVASCRIPT (/ˈdʒɑːvəˌskrɪpt/ ), often abbreviated as JS, is a high-level , dynamic , weakly typed , object-based , multi-paradigm , and interpreted programming language . Alongside HTML
HTML
and CSS
CSS
, JavaScript
JavaScript
is one of the three core technologies of World Wide Web content production . It is used to make webpages interactive and provide online programs, including video games. The majority of websites employ it, and all modern web browsers support it without the need for plug-ins by means of a built-in JavaScript engine
JavaScript engine
. Each of the many JavaScript
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.

As a multi-paradigm language, JavaScript
JavaScript
supports event-driven , functional , and imperative (including object-oriented and prototype-based ) programming styles . It has an API
API
for working with text, arrays , dates, regular expressions , and basic manipulation of the DOM , but does not include any I/O , such as networking, storage, or graphics facilities, relying for these upon the host environment in which it is embedded.

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
JavaScript
available for writing mobile and desktop applications, including desktop widgets.

Although there are strong outward similarities between JavaScript
JavaScript
and Java, including language name, syntax , and respective standard libraries , the two languages are distinct and differ greatly in design; JavaScript
JavaScript
was influenced by programming languages such as Self and Scheme .

CONTENTS

* 1 History

* 1.1 Beginnings at Netscape
Netscape
* 1.2 Server-side JavaScript
JavaScript
* 1.3 Adoption by Microsoft
Microsoft
* 1.4 Standardization * 1.5 Later developments

* 2 Trademark * 3 Vanilla JavaScript
JavaScript

* 4 Features

* 4.1 Universal support * 4.2 Imperative and structured * 4.3 Dynamic * 4.4 Prototype-based (object-oriented) * 4.5 Functional * 4.6 Delegative * 4.7 Miscellaneous * 4.8 Vendor-specific extensions

* 5 Syntax

* 5.1 Simple examples * 5.2 More advanced example

* 6 Use in Web pages

* 6.1 Example script * 6.2 Compatibility considerations

* 7 Security

* 7.1 Cross-site vulnerabilities * 7.2 Misplaced trust in the client * 7.3 Misplaced trust in developers * 7.4 Browser and plugin coding errors * 7.5 Sandbox implementation errors * 7.6 Hardware vulnerabilities

* 8 Uses outside Web pages

* 8.1 Embedded scripting language * 8.2 Scripting engine * 8.3 Application platform

* 9 Development tools * 10 Benchmark tools for developers * 11 Version history

* 12 Related languages and features

* 12.1 Use as an intermediate language * 12.2 JavaScript
JavaScript
and Java

* 13 See also * 14 References * 15 Further reading * 16 External links

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
Web browser
, which played an important part in expanding the growth of the nascent World Wide Web . 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
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
Netscape
Navigator in the same year, and the company took the name Netscape Communications.

Netscape
Netscape
Communications realized that the Web needed to become more dynamic. Marc Andreessen , the founder of the company believed that HTML
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, the company recruited Brendan Eich with the goal of embedding the Scheme programming language into its Netscape
Netscape
Navigator. Before he could get started, Netscape
Netscape
Communications collaborated with Sun Microsystems to include in Netscape
Netscape
Navigator Sun's more static programming language Java , in order to compete with Microsoft
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
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
Netscape
Navigator 2.0 in September 1995, but it was renamed JAVASCRIPT when it was deployed in the Netscape
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
Netscape
to give JavaScript
JavaScript
the cachet of what was then the hot new Web programming language.

There is a common misconception that JavaScript
JavaScript
was influenced by an earlier Web page scripting language developed by Nombas named C-- (not to be confused with the later C-- created in 1997). Brendan Eich, however, had never heard of C-- 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
JavaScript
instead of C-- in their ScriptEase product and was part of the TC39 group that standardized ECMAScript.

SERVER-SIDE JAVASCRIPT

In December 1995, soon after releasing JavaScript
JavaScript
for browsers, Netscape
Netscape
introduced an implementation of the language for server-side scripting with Netscape
Netscape
Enterprise Server .

Since the mid-2000s, additional server-side JavaScript implementations have been introduced, such as Node.js in 2009.

ADOPTION BY MICROSOFT

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
Internet Explorer 3
. JScript was also available for server-side scripting in Internet Information Server . Internet Explorer 3
Internet Explorer 3
also included Microsoft's first support for CSS
CSS
and various extensions to HTML, but in each case the implementation was noticeably different to 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
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
Internet Explorer 4
, Microsoft
Microsoft
introduced the concept of Dynamic HTML
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
JavaScript
on the Web.

STANDARDIZATION

In November 1996, Netscape
Netscape
submitted JavaScript
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
JavaScript
being the most well known of the implementations. ActionScript and JScript are other well-known implementations of ECMAScript, with extensions.

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
Google
) started in 2000 and at first, Microsoft
Microsoft
seemed to participate and even implemented some of the proposals in their JScript .NET language.

Over time it was clear though that Microsoft
Microsoft
had no intention of cooperating or implementing proper JavaScript
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
Mozilla
rejoined Ecma International as a not-for-profit member and work started on ECMAScript for XML
XML
(E4X), the ECMA-357 standard, which came from ex- Microsoft
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
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
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
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
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
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". The advent of Ajax returned JavaScript
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
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
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
Netscape
Communications and current entities such as the Mozilla Foundation .

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
JavaScript
code.

FEATURES

The following features are common to all conforming ECMAScript implementations, unless explicitly specified otherwise.

UNIVERSAL SUPPORT

All modern Web browsers support JavaScript
JavaScript
with built-in interpreters.

IMPERATIVE AND STRUCTURED

JavaScript
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
JavaScript
originally had only function scoping with var. ECMAScript 2015 added keywords let and const for block scoping, meaning JavaScript
JavaScript
now has both function and block scoping. Like C, JavaScript
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 As with most scripting languages , JavaScript
JavaScript
is dynamically typed ; a type is associated with each value , rather than just with each expression. For example, a variable that is at one time bound to a number may later be re-bound to a string . JavaScript
JavaScript
supports various ways to test the type of an object, including duck typing . Run-time evaluation JavaScript
JavaScript
includes an eval function that can execute statements provided as strings at run-time.

PROTOTYPE-BASED (OBJECT-ORIENTED)

JavaScript
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 = 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
JavaScript
has a small number of built-in objects, including Function and Date. Prototypes JavaScript
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
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
JavaScript
also supports anonymous functions .

DELEGATIVE

JavaScript
JavaScript
supports implicit and explicit delegation . Functions as roles (Traits and Mixins) JavaScript
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
JavaScript
is covered by a delegation automatism that is bound to the prototype property of constructor functions.

MISCELLANEOUS

Run-time environment JavaScript
JavaScript
typically relies on a run-time environment (e.g., a Web browser
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
HTML
elements). This is not a language feature per se, but it is common in most JavaScript
JavaScript
implementations. JavaScript
JavaScript
processes messages from a queue one at a time. Upon loading a new message, JavaScript
JavaScript
calls a function associated with that message, which creates a call stack frame (the function's arguments and local variables ). The call stack shrinks and grows based on the function's needs. Upon function completion, when the stack is empty, JavaScript
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 model describes the event loop as non-blocking : program input/output is performed using events and callback functions . This means, for instance, that JavaScript
JavaScript
can process a mouse click while waiting for a database query to return information. Variadic functions An indefinite number of parameters can be passed to a function. The function can access them through formal parameters and also through the local arguments object. Variadic functions can also be created by using the bind method. 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 literals form the basis of the JSON data format. Regular expressions JavaScript
JavaScript
also supports regular expressions 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.

VENDOR-SPECIFIC EXTENSIONS

JavaScript
JavaScript
is officially managed by Mozilla Foundation , and new language features are added periodically. However, only some JavaScript
JavaScript
engines support these new features:

* property getter and setter functions (supported by WebKit, Gecko, Opera, ActionScript, and Rhino) * conditional catch clauses * iterator protocol (adopted from Python ) * shallow generators -coroutines (adopted from Python) * array comprehensions and generator expressions (adopted from Python) * proper block scope via the let keyword * array and object destructuring (limited form of pattern matching ) * concise function expressions (function(args) expr) * ECMAScript for XML
XML
(E4X), an extension that adds native XML support to ECMAScript (unsupported in Firefox
Firefox
since version 21 )

SYNTAX

Main article: JavaScript syntax

SIMPLE EXAMPLES

Variables in JavaScript
JavaScript
can be defined using the var keyword:

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 entitled "Hello, World!"

Note the comments in the example above, both of which were preceded with two forward slashes .

There is no built-in I/O functionality in JavaScript; the run-time environment provides that. The ECMAScript specification in edition 5.1 mentions:

… indeed, there are no provisions in this specification for input of external data or output of computed results.

However, most runtime environments have a console object that can be used to print output. Here is a minimalist Hello World program in JAVASCRIPT:

console.log("Hello World!");

A simple recursive function:

function factorial(n) { if (n === 0 n === 1) { return 1; // 0! = 1! = 1 } return n * factorial(n - 1); } factorial(3); // returns 6

An anonymous function (or lambda):

function counter() { var count = 0; return function() { return ++count; }; } var closure = counter(); closure(); // returns 1 closure(); // returns 2 closure(); // returns 3

In JavaScript, objects are created in the same way as functions, this is known as a function object .

Object example:

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

This example shows that, in JavaScript, function closures capture their non-local variables _by reference_.

Variadic function demonstration (arguments is a special variable ):

function sum() { var x = 0; for (var i = 0; i

* _ MSN TV _

* Software no longer in development shown in _italics_

* Category
Category
* Commons * Internet portal * Software portal

* v * t * e

Node.js

PLATFORM

* Node.js * NPM * V8 * CommonJS

FRAMEWORKS

* MEAN

* MongoDB * Express.js * AngularJS /Angular

* MEEN (substituted with Ember.js ) * Backbone.js
Backbone.js
* Meteor

LIBRARIES

* Lodash * Underscore.js * React.js

LANGUAGES

* JavaScript * CoffeeScript * TypeScript
TypeScript

HOSTS

* Joyent * Nodejitsu * OpenShift
OpenShift
* Linode * DigitalOcean

AUTHORITY CONTROL

* LCCN : sh96004880 * GND : 4420180-1 * SUDOC : 034781870 * BNF : cb12549978q (data) * BNE : XX542465

Retrieved from "https://en.wikipedia.org/w/index.php?title= JavaScript
JavaScript
additional terms may apply. By using this site, you agree to the Terms of Use an