All Topics  
JavaScript

 

   Email Print
   Bookmark   Link






 

JavaScript



 
 
JavaScript is a scripting language
Scripting language

A scripting language, script language or extension language, is a programming language that allows some control of a single or many Application software....
 widely used for client-side
Client-side

In computer networking, the term client-side refers to operations that are performed by the Client in a client-server relationship.Typically, a client is a computer application, such as a web browser, that runs on a user 's local computer or workstation and connects to a server as necessary....
 web development. It was the originating dialect
Programming language dialect

A dialect of a programming language is a variation or extension of the language that does not change its intrinsic nature. With languages such as Scheme and Forth , standards may be considered insufficient, inadequate or even illegitimate by implementors, so often they will deviate from the standard, making a new dialect....
 of the ECMAScript
ECMAScript

ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 Specification . The language is widely used on the World Wide Web, and is often confused with JavaScript or JScript, the two major Programming language dialect from which ECMAScript was standardized....
 standard. It is a dynamic, weakly typed
Weak typing

In computer science, weak typing is a property attributed to the type systems of some programming languages. It is the opposite of strong typing, and consequently the term weak typing has as many different meanings as strong typing does ....
, prototype-based
Prototype-based programming

Prototype-based programming is a style of object-oriented programming in which class es are not present, and behavior reuse is performed via a process of cloning existing object s that serve as prototypes....
 language with first-class function
First-class function

In computer science, a programming language is said to support first-class functions if it treats function s as first-class objects. Specifically, this means that the language supports constructing new functions during the execution of a program, storing them in data structures, passing them as arguments to other functions, and returning the...
s. JavaScript was influenced by many languages and was designed to look like Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
, but be easier for non-programmers to work with.

Although best known for its use in website
Website

A Web site is a collection of related Web pages, images, videos or other digital assets that are hosted on one Web server, usually accessible via the Internet....
s (as client-side JavaScript
Client-side JavaScript

Client-side JavaScript is JavaScript that runs on client-side, i.e. the web browser, hence is for client-side scripting. While JavaScript was originally created to run on client-side, this term was coined because the language is no longer limited to just client-side, e.g....
), JavaScript is also used to enable scripting access to objects embedded in other applications.

JavaScript, despite the name, is essentially unrelated to the Java programming language, although both have the common C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
 syntax
Curly bracket programming language

Curly brace or bracket programming languages are those which use balanced brackets to make block s in their syntax or formal grammar, mainly due to being C -influenced....
, and JavaScript copies many Java names and naming conventions.






Discussion
Ask a question about 'JavaScript'
Start a new discussion about 'JavaScript'
Answer questions from other users
Full Discussion Forum



Encyclopedia


JavaScript is a scripting language
Scripting language

A scripting language, script language or extension language, is a programming language that allows some control of a single or many Application software....
 widely used for client-side
Client-side

In computer networking, the term client-side refers to operations that are performed by the Client in a client-server relationship.Typically, a client is a computer application, such as a web browser, that runs on a user 's local computer or workstation and connects to a server as necessary....
 web development. It was the originating dialect
Programming language dialect

A dialect of a programming language is a variation or extension of the language that does not change its intrinsic nature. With languages such as Scheme and Forth , standards may be considered insufficient, inadequate or even illegitimate by implementors, so often they will deviate from the standard, making a new dialect....
 of the ECMAScript
ECMAScript

ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 Specification . The language is widely used on the World Wide Web, and is often confused with JavaScript or JScript, the two major Programming language dialect from which ECMAScript was standardized....
 standard. It is a dynamic, weakly typed
Weak typing

In computer science, weak typing is a property attributed to the type systems of some programming languages. It is the opposite of strong typing, and consequently the term weak typing has as many different meanings as strong typing does ....
, prototype-based
Prototype-based programming

Prototype-based programming is a style of object-oriented programming in which class es are not present, and behavior reuse is performed via a process of cloning existing object s that serve as prototypes....
 language with first-class function
First-class function

In computer science, a programming language is said to support first-class functions if it treats function s as first-class objects. Specifically, this means that the language supports constructing new functions during the execution of a program, storing them in data structures, passing them as arguments to other functions, and returning the...
s. JavaScript was influenced by many languages and was designed to look like Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
, but be easier for non-programmers to work with.

Although best known for its use in website
Website

A Web site is a collection of related Web pages, images, videos or other digital assets that are hosted on one Web server, usually accessible via the Internet....
s (as client-side JavaScript
Client-side JavaScript

Client-side JavaScript is JavaScript that runs on client-side, i.e. the web browser, hence is for client-side scripting. While JavaScript was originally created to run on client-side, this term was coined because the language is no longer limited to just client-side, e.g....
), JavaScript is also used to enable scripting access to objects embedded in other applications.

JavaScript, despite the name, is essentially unrelated to the Java programming language, although both have the common C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
 syntax
Curly bracket programming language

Curly brace or bracket programming languages are those which use balanced brackets to make block s in their syntax or formal grammar, mainly due to being C -influenced....
, and JavaScript copies many Java names and naming conventions. The language's name is the result of a co-marketing deal between Netscape
Netscape

Netscape Communications is a United States computer services company, best known for its web browser. The browser was once dominant in terms of Usage share of web browsers, but lost most of that share to Internet Explorer during the browser wars....
 and Sun
Sun Microsystems

Sun Microsystems, Inc. is a multinational corporation vendor of computers, computer components, computer software, and information technology services, founded on February 24, 1982....
, in exchange for Netscape bundling Sun's Java runtime with their then-dominant browser
Web browser

A Web browser is a application software which enables a user to display and interact with text, images, videos, music, games and other information typically located on a Web page at a website on the World Wide Web or a local area network....
. The key design principles within JavaScript are inherited from the Self and Scheme programming languages.

"JavaScript" is a trademark
TradeMark

TradeMark is a tall, primarily residential, skyscraper in Charlotte, North Carolina. It was completed in 2007 and has 28 floors. There are 200 hundred residential units....
 of Sun Microsystems. It was used under license for technology invented and implemented by Netscape Communications and current entities such as the Mozilla Foundation
Mozilla Foundation

The Mozilla Foundation is a non-profit organization that exists to support and provide leadership for the open source Mozilla project. The organization sets the policies that govern development, operate key infrastructure and control trademarks and other intellectual property....
.

History and naming


JavaScript was originally developed by Brendan Eich
Brendan Eich

Brendan Eich is a computer programmer and creator of the JavaScript programming language. He is the Chief Technology Officer at the Mozilla Corporation....
 of Netscape under the name Mocha, which was later renamed to LiveScript, and finally to JavaScript. The change of name from LiveScript to JavaScript roughly coincided with Netscape adding support for Java technology in its Netscape Navigator
Netscape Navigator

Netscape Navigator and Netscape are the names for the proprietary software web browser popular in the 1990s, and the flagship product of the Netscape Communications Corporation, and the dominant web browser in terms of Usage share of web browsers....
 web browser
Web browser

A Web browser is a application software which enables a user to display and interact with text, images, videos, music, games and other information typically located on a Web page at a website on the World Wide Web or a local area network....
. JavaScript was first introduced and deployed in the Netscape browser version 2.0B3 in December 1995. The naming has caused confusion, giving the impression that the language is a spin-off of Java, and it has been characterized by many as a marketing ploy by Netscape to give JavaScript the cachet of what was then the hot new web-programming language.

Due to the widespread success of JavaScript as a client-side scripting language for web pages, Microsoft
Microsoft

Microsoft Corporation is a multinational corporation computer technology corporation that develops, manufactures, licenses, and supports a wide range of computer software products for computing devices....
 developed a compatible dialect of the language, naming it JScript
JScript

JScript is the Microsoft dialect of the ECMAScript scripting language specification.JavaScript , JScript, and ECMAScript are very similar languages....
 to avoid trademark issues. JScript added new date methods to fix the non-Y2K
Year 2000 problem

The Year 2000 problem was a notable computer bug resulting from the practice in early computer program design of representing the year with two digits....
-friendly methods in JavaScript, which were based on . JScript was included in Internet Explorer
Internet Explorer

Windows Internet Explorer , commonly abbreviated to IE, is a series of graphical user interface web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems starting in 1995....
 3.0, released in August 1996. The dialects are perceived to be so similar that the terms "JavaScript" and "JScript" are often used interchangeably. Microsoft, however, notes dozens of ways in which JScript is .

Netscape submitted JavaScript to Ecma International
Ecma International

'Ecma International' is an international, private non-profit standards organization for information and communication systems. It acquired its name in 1994, when the European Computer Manufacturers Association changed its name to reflect the organization's international reach....
 for standardization resulting in the standardized version named ECMAScript
ECMAScript

ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 Specification . The language is widely used on the World Wide Web, and is often confused with JavaScript or JScript, the two major Programming language dialect from which ECMAScript was standardized....
.

The flexibility of JavaScript has made it one of the most popular programming languages on the web and also one of the easier languages to learn. Initially, however, many professional programmers denigrated the language because its target audience was web authors and other such "amateurs", among other reasons. The advent of AJAX
Ajax (programming)

Ajax, or AJAX , is a group of interrelated web development techniques used to create interactive web applications or rich Internet applications....
 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 of the web.

Features


Imperative and structured

JavaScript supports all the structured programming
Structured programming

Structured programming can be seen as a subset or subdiscipline of procedural programming, one of the major programming paradigms. It is most famous for removing or reducing reliance on the GOTO Statement ....
 syntax in C (e.g., if statements, while loops, switch statements, etc.). One partial exception is scoping: C-style block-level scoping is not supported. JavaScript 1.7, however, supports block-level scoping with the let keyword. Like C, JavaScript makes a distinction between expressions
Expression (programming)

An expression in a programming language is a combination of value s, variables, operator s, and function s that are interpreted according to the particular Order of operations and of association for a particular programming language, which computes and then produces another value....
 and statements
Statement (programming)

In computer programming a statement can be thought of as the smallest standalone element of an imperative programming language. A program is formed by a sequence of one or more statements....
.

Dynamic

dynamic typing: As in most scripting languages, types
Type system

In computer science, a type system may be defined as "a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute."....
 are associated with values
Value (computer science)

In computer science, a value is a sequence of bits that is interpreted according to some data type. It is possible for the same sequence of bits to have different values, depending on the type used to interpret its meaning....
, not variables. For example, a variable x could be bound to a number, then later rebound to a string
String (computer science)

In computer programming and some branches of mathematics, a string is an ordered sequence of symbols. These symbols are chosen from a predetermined set or alphabet....
. JavaScript supports various ways to test the type of an object, including duck typing
Duck typing

In computer programming, duck typing is a style of dynamic typing in which an object's current set of Method s and properties determines the valid semantics, rather than its inheritance from a particular class or implementation of a specific interface....
. objects as associative arrays: JavaScript is almost entirely object-based
Object-based

In general, object-based indicates that something such as a theory, language, or model is based on the concept of Object .In computer science, the term object-based has two different, incompatible senses:...
. Objects
Object (computer science)

In its simplest embodiment, an object is an allocated region of storage. Since programming languages use variable#Computer_programmings to access objects, the terms object and variable are often used interchangeably....
 are associative array
Associative array

An associative array is an abstract data type composed of a Collection of unique keys and a collection of values, where each key is associated with one value ....
s, augmented with prototypes (see below). Object property names are associative array keys: obj.x = 10 and obj["x"] = 10 are equivalent, the dot notation being merely syntactic sugar
Syntactic sugar

Syntactic sugar is a term coined by Peter J. Landin for additions to the syntax of a computer language that do not affect its Function but make it "sweeter" for humans to use....
. Properties and their values can be added, changed, or deleted at run-time. The properties of an object can also be enumerated via a for...in loop. run-time evaluation: JavaScript includes an eval
Eval

In some programming languages, eval is a subroutine which evaluates a string as though it were an expression and returns a result; in others, it executes multiple lines of code as though they had been included instead of the line including the eval....
 function that can execute statements provided as strings at run-time.

Functional

first-class functions: Functions
Subroutine

In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code....
 are first-class
First-class function

In computer science, a programming language is said to support first-class functions if it treats function s as first-class objects. Specifically, this means that the language supports constructing new functions during the execution of a program, storing them in data structures, passing them as arguments to other functions, and returning the...
; they are objects themselves. As such, they have properties and can be passed around and interacted with like any other object. inner functions and closures: Inner functions (functions defined within other functions) are created each time the outer function is invoked, and variables of the outer functions for that invocation continue to exist as long as the inner functions still exist, even after that invocation is finished (e.g. if the inner function was returned, it still has access to the outer function's variables) — this is the mechanism behind closure
Closure (computer science)

In computer science, a closure is a function that is evaluated in an environment containing one or more bound variables. When called, the function can access these variables....
s within JavaScript.

Prototype-based

prototypes: JavaScript uses prototypes
Prototype-based programming

Prototype-based programming is a style of object-oriented programming in which class es are not present, and behavior reuse is performed via a process of cloning existing object s that serve as prototypes....
 instead of classes
Class (computer science)

In object-oriented programming, a class is a programming language construct that is used as a blueprint to create Object s. This blueprint includes Attribute s and Method s that the created objects all share....
 for defining object properties, including methods
Method (computer science)

In object-oriented programming, a method is a subroutine that is exclusively associated either with a class or with an object . Like a procedure in procedural programming languages, a method usually consists of a sequence of statement to perform an action, a set of input parameter to customize those actions, and possibly an output value...
, and inheritance
Inheritance (computer science)

In object-oriented programming, inheritance is a way to form new class es using classes that have already been defined. The inheritance concept was invented in 1967 for Simula....
. 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 creates a new object and calls that function with its local this keyword bound to that object for that invocation. The function's prototype property determines the new object's prototype. functions as methods: Unlike many object-oriented languages, there is no distinction between a function definition and a method
Method (computer science)

In object-oriented programming, a method is a subroutine that is exclusively associated either with a class or with an object . Like a procedure in procedural programming languages, a method usually consists of a sequence of statement to perform an action, a set of input parameter to customize those actions, and possibly an output value...
 definition. Rather, the distinction occurs during function calling; a function can be called as a method. When a function is invoked as a method of an object, the function's local this keyword is bound to that object for that invocation.

Miscellaneous

run-time environment: JavaScript typically relies on a run-time environment (e.g. in a web browser) to provide objects and methods by which scripts can interact with "the outside world". (This is not a language feature per se, but it is common in most JavaScript implementations.) variadic functions: An indefinite number of parameters can be passed to a function. The function can both access them through formal parameters and the local arguments object. 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
Object literal

In computer science, a literal is a notation for representing a fixed Value in source code. Almost all programming languages have notations for atomic values such as integer s, floating-point numbers, string s, and Boolean datatype; some also have notations for enumerated type and compound values such as arrays, record s, and object s....
 form the basis of the JSON
JSON

JSON , short for JavaScript Object Notation, is a lightweight computer data interchange format. It is a text-based, human-readable format for representing simple data structures and associative arrays ....
 data format. regular expressions: JavaScript also supports regular expression
Regular expression

In computing, regular expressions provide a concise and flexible means for identifying strings of text of interest, such as particular characters, words, or patterns of characters....
s in a manner similar to Perl
Perl

In computer programming, Perl is a high-level programming language, List of programming languages by category, Interpreter , dynamic programming language....
, which provide a concise and powerful syntax for text manipulation that is more sophisticated than the built-in string functions.

Syntax and semantics


As of 2008, the latest version of the language is JavaScript 1.8. It is a superset of ECMAScript
ECMAScript

ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 Specification . The language is widely used on the World Wide Web, and is often confused with JavaScript or JScript, the two major Programming language dialect from which ECMAScript was standardized....
 (ECMA-262) Edition 3. Extensions to the language, including partial E4X
E4X

ECMAScript for XML is a programming language extension that adds native XML support to ECMAScript . The goal is to provide an alternative to Document Object Model interfaces that uses a simpler syntax for accessing XML documents....
 (ECMA-357) support and experimental features considered for inclusion into ECMAScript Edition 4, are documented .

Sample code: function LCMCalculator(x, y) LCMCalculator.prototype = ; 25,55],[21,56],[22,58],[28,56.map(function(pair) ).sort(function(a, b) ).forEach(function(obj) ); // Note: Array's map and forEach is predefined in JavaScript 1.6.

The output is:
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


Use in web pages


The primary use of JavaScript is to write functions that are embedded in or included from HTML
HTML

HTML, an Acronym and initialism of HyperText Markup Language, is the predominant markup language for Web pages. It provides a means to describe the structure of text-based information in a document?by denoting certain text as links, headings, paragraphs, lists, and so on?and to supplement that text with interactive forms, embedded '...
 pages and interact with the Document Object Model
Document Object Model

The Document Object Model is a platform- and programming language-independent standard object model for representing HTML or XML documents as well as an Application Programming Interface for querying, traversing and manipulating such documents....
 (DOM) of the page. Some simple examples of this usage are:

  • Opening or popping up
    Pop-up ad

    Pop-up ads or pop-ups are a form of online advertising on the WWW World Wide Web intended to attract web traffic or capture email addresses....
     a new window with programmatic control over the size, position, and attributes of the new window (i.e. whether the menus, toolbars, etc. are visible).
  • Validation
    Validation

    The word validation has several uses:* In common usage, validation is the process of checking if something satisfies a certain criterion. Examples would include checking if a statement is true , if an appliance works as intended, if a computer system is secure, or if computer data are compliant with an open standard....
     of web form
    Form (web)

    A webform on a web page allows a user to enter data that is sent to a Server for processing. Webforms resemble form because internet users fill out the forms using checkboxes, radio buttons, or menus....
     input values to make sure that they will be accepted before they are submitted to the server.
  • Changing images as the mouse cursor moves over them
    Rollover (web design)

    Rollover refers to a button as created by a web developer or web designer, found within a web page, used to provide interactivity between the user and the page itself....
    : This effect is often used to draw the user's attention to important links displayed as graphical elements.


Because JavaScript code can run locally in a user's browser (rather than on a remote server) it can respond to user actions quickly, making an application feel more responsive. Furthermore, JavaScript code can detect user actions which HTML alone cannot, such as individual keystrokes. Applications such as Gmail
Gmail

Gmail is a free Post Office Protocol and Internet Message Access Protocol webmail service provided by Google. In the United Kingdom and Germany it is officially called Google Mail....
 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
Ajax

Ajax may refer to:...
 similarly exploits this strength.

A JavaScript engine (also known as JavaScript interpreter or JavaScript implementation) is an interpreter
Interpreter (computing)

In computer science, an interpreter normally means a computer program that execution , i.e. performs, instructions written in a programming language....
 that interprets JavaScript source code
Source code

In computer science, source code is any collection of statements or declarations written in some human-readable computer programming language....
 and executes the script
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
 accordingly. The first ever JavaScript engine was created by Brendan Eich
Brendan Eich

Brendan Eich is a computer programmer and creator of the JavaScript programming language. He is the Chief Technology Officer at the Mozilla Corporation....
 at Netscape Communications Corporation, for the Netscape Navigator
Netscape Navigator

Netscape Navigator and Netscape are the names for the proprietary software web browser popular in the 1990s, and the flagship product of the Netscape Communications Corporation, and the dominant web browser in terms of Usage share of web browsers....
 web browser
Web browser

A Web browser is a application software which enables a user to display and interact with text, images, videos, music, games and other information typically located on a Web page at a website on the World Wide Web or a local area network....
. The engine, code-named SpiderMonkey, is implemented in C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
. It has since been updated (in JavaScript 1.5) to conform to ECMA-262 Edition 3. The Rhino
Rhino (JavaScript engine)

Rhino is an open source JavaScript engine. It is developed entirely in Java and managed by the Mozilla Foundation. The Foundation also provides an implementation of JavaScript in C known as SpiderMonkey ....
 engine, created primarily by Norris Boyd (also at Netscape) is a JavaScript implementation in Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
. Rhino, like SpiderMonkey, is ECMA-262 Edition 3 compliant.

The most common host environment for JavaScript is by far a web browser. Web browsers typically use the public API
Application programming interface

An application programming interface is a set of subroutine, data structures, class and/or Protocol provided by library and/or operating system Service s in order to support the building of applications....
 to create "host objects" responsible for reflecting the DOM
Document Object Model

The Document Object Model is a platform- and programming language-independent standard object model for representing HTML or XML documents as well as an Application Programming Interface for querying, traversing and manipulating such documents....
 into JavaScript. The web server
Web server

The term web server can mean one of two things:# A computer program that is responsible for accepting Hypertext Transfer Protocol requests from clients , and Server them HTTP responses along with optional data contents, which usually are web pages such as Hypertext Markup Language documents and linked objects ....
 is another common application of the engine. A JavaScript webserver
Server-side JavaScript

Server-side JavaScript refers to JavaScript that runs on server-side. This term was coined because the language is predominantly used on the client-side, i.e....
 would expose host objects representing an HTTP request and response objects, which a JavaScript program could then manipulate to dynamically generate web pages.

A minimal example of a web page containing JavaScript (using HTML 4.01
HTML

HTML, an Acronym and initialism of HyperText Markup Language, is the predominant markup language for Web pages. It provides a means to describe the structure of text-based information in a document?by denoting certain text as links, headings, paragraphs, lists, and so on?and to supplement that text with interactive forms, embedded '...
 syntax) would be: simple page

Compatibility considerations


The DOM
Document Object Model

The Document Object Model is a platform- and programming language-independent standard object model for representing HTML or XML documents as well as an Application Programming Interface for querying, traversing and manipulating such documents....
 interfaces for manipulating web pages are not part of the ECMAScript standard, or of JavaScript itself. Officially, they are defined by a separate standardization effort by the W3C
World Wide Web Consortium

The World Wide Web Consortium is the main international standards organization for the World Wide Web . It is arranged as a consortium where member organizations maintain full-time staff for the purpose of working together in the development of standards for the World Wide Web....
; in practice, browser implementations differ from the standards and from each other, and not all browsers execute JavaScript.

To deal with these differences, JavaScript authors can attempt to write standards-compliant code which 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. 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. Programmers may also use libraries or toolkits which take browser differences into account.

Furthermore, scripts will not work for all users. For example, a user may:

  • use an old or rare browser with incomplete or unusual DOM support,
  • use a PDA
    Personal digital assistant

    A personal digital assistant is a handheld computer, also known as a palmtop computer. Newer PDAs also have both color screens and audio capabilities, enabling them to be used as mobile phones, , web browsers, or portable media players....
     or mobile phone
    Mobile phone

    A mobile phone is a long-range, electronic device used for mobile voice or data communication over a network of specialized base stations known as cell sites....
     browser which cannot execute JavaScript,
  • have JavaScript execution disabled as a security precaution,
  • or be visually or otherwise disabled and use a speech browser


To support these users, web authors can try to create pages which degrade gracefully
Fault-tolerant system

Fault-tolerance or graceful degradation is the property that enables a system to continue operating properly in the event of the failure of some of its components....
 on user agents (browsers) which do not support the page's JavaScript.

Security

JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the web. Browser authors contain this risk using two restrictions. First, scripts run in a sandbox
Sandbox (computer security)

In computer security, a sandbox is a security mechanism for safely running programs. It is often used to execute untested code, or untrusted programs from unverified third-parties, suppliers and untrusted users....
 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
Same origin policy

In computing, the same origin policy is an important computer security concept for a number of client-side scripting, such as JavaScript. In a nutshell, the policy permits scripts running on pages originating from the same site to access each other's methods and properties with no specific restrictions — but prevents access to most meth...
: 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.

Cross-site vulnerabilities

A common JavaScript-related security problem is cross-site scripting
Cross-site scripting

Cross-site scripting is a type of computer insecurity vulnerability typically found in web applications which allow code injection by malicious web users into the web pages viewed by other users....
, or XSS, a violation of the same-origin policy
Same origin policy

In computing, the same origin policy is an important computer security concept for a number of client-side scripting, such as JavaScript. In a nutshell, the policy permits scripts running on pages originating from the same site to access each other's methods and properties with no specific restrictions — but prevents access to most meth...
. 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.

XSS vulnerabilities can also occur because of implementation mistakes by browser authors.

Another cross-site vulnerability is cross-site request forgery
Cross-site request forgery

Cross-site request forgery, also known as one-click attack or session riding and abbreviated as CSRF or XSRF, is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts....
 or 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.

"JavaScript hijacking" is a type of CSRF attack in which a provides a limited version of the JavaScript debugging functionality in Microsoft Visual Studio.

Web applications within Firefox can be debugged using the Firebug
Firebug (Firefox extension)

The Firebug extension for Mozilla Firefox allows the debugging, editing, and monitoring of any website's CSS, HTML, Document Object Model, and JavaScript, and provides other Web development....
 plug-in, or the older Venkman
Venkman

Venkman is the JavaScript debugger component of the Mozilla Application Suite. It is also available as a Mozilla Firefox Add-on . Venkman is named after the character Dr....
 debugger, which also works with the Mozilla
Mozilla

Mozilla was the official, public, original name of Mozilla Application Suite by the Mozilla Foundation, currently known as SeaMonkey internet suite....
 browser. Firefox also has a simpler built-in Error Console, which logs and evaluates JavaScript. It also logs CSS
CSS

CSS may stand for:...
 errors and warnings.

WebKit
WebKit

WebKit is an application framework that provides a foundation upon which to build a web browser. WebKit was originally derived by Apple Inc. from the Konqueror browser?s KHTML software library for use as the engine of Mac OS X?s Safari web browser, and has now been further developed by individuals from the KDE project, Apple, Nokia, Google,...
's Web Inspector includes a JavaScript debugger on Macintosh and Windows powering Apple's Safari
Safari (web browser)

Safari is a web browser developed by Apple Inc.. First released as a beta on January 7, 2003 on the company's Mac OS X operating system, it became Apple's default browser beginning with Mac OS X v10.3, commonly known as "OS X Panther." Apple has also made Safari the native browser for the iPhone OS....
.

Some debugging aids are themselves bits of JavaScript code built to run on the Web. scans code for violations of a standard coding style. [https://www.squarefree.com/bookmarklets/webdevel.html Web development bookmarklets] and provide variations on the idea of the cross-browser JavaScript console.

There is a non-free tool called SplineTech JavaScript HTML Debugger.

Since JavaScript is interpreted, loosely-typed, and may be hosted in varying environments, each incompatible with the others, a programmer has to take extra care to make sure the code executes as expected in as wide a range of circumstances as possible, and that functionality degrades gracefully when it does not.

Versions

Version Release date Equivalent to Netscape
Navigator
Mozilla
Firefox
Internet
Explorer
Opera Safari Google
Chrome
1.0 March 1996 2.0 3.0  
1.1 August 1996 3.0  
1.2 June 1997 4.0-4.05  
1.3 October 1998 ECMA-262 1st edition / ECMA-262 2nd edition 4.06-4.7x 4.0  
1.4 Netscape
Server
 
1.5 November 2000 ECMA-262 3rd edition 6.0 1.0 5.5 (JScript 5.5),
6 (JScript 5.6),
7 (JScript 5.7),
8 (JScript 6)
6.0,
7.0,
8.0,
9.0
 
1.6 November 2005 1.5 + Array extras + Array and String generics + E4X 1.5 3.x
1.7 October 2006 1.6 + Pythonic generators + Iterators + let 2.0  
1.8 June 2008 1.7 + Generator expressions + Expression closures 3.0  
1.9 1.8 + New Features 3.1  


The next major version of JavaScript, 2.0, will conform to ECMA-262 4th edition
ECMAScript

ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 Specification . The language is widely used on the World Wide Web, and is often confused with JavaScript or JScript, the two major Programming language dialect from which ECMAScript was standardized....
.

Related languages


The standardization effort for JavaScript needed to avoid trademark issues, so the ECMA 262 standard calls the language ECMAScript
ECMAScript

ECMAScript is a scripting language, standardized by Ecma International in the ECMA-262 Specification . The language is widely used on the World Wide Web, and is often confused with JavaScript or JScript, the two major Programming language dialect from which ECMAScript was standardized....
, three editions of which have been published since the work started in November 1996.

Objective-J
Objective-J

Objective-J is a programming language developed as part of the Cappuccino web development framework. Its syntax is nearly identical to the Objective-C syntax and it shares with JavaScript the same relationship that Objective-C has with the C programing language: that of being a strict, but small, superset; adding traditional Inheritance an...
 is a strict superset of JavaScript that adds traditional inheritance and Smalltalk
Smalltalk

Smalltalk is an Object-oriented programming, Type system, reflection computer programming programming language. Smalltalk was created as the language to underpin the "new world" of computing exemplified by "human?computer symbiosis." It was designed and created in part for educational use, more so for constructionist learning, at PARC by Al...
/Objective-C
Objective-C

Objective-C is a Reflection , Object-oriented programming programming language which adds Smalltalk-style message passing to C .Today it is used primarily on Mac OS X, iPhone OS, and GNUstep, three environments based on the OpenStep standard, and is the primary language used for the NEXTSTEP, OpenStep#OPENSTEP, and Cocoa application framew...
 style dynamic dispatch and optional pseudo-static typing to pure JavaScript.

Microsoft's VBScript
VBScript

VBScript is an Active Scripting language, developed by Microsoft, which uses the Component Object Model to access elements of the environment within which it's running ....
, like JavaScript, can be run client-side in web pages. VBScript has syntax derived from Visual Basic
Visual Basic

'Visual Basic' is the third-generation programming language event-driven programming and integrated integrated development environment from Microsoft for its Component Object Model programming model....
 and is only supported by Microsoft's Internet Explorer
Internet Explorer

Windows Internet Explorer , commonly abbreviated to IE, is a series of graphical user interface web browsers developed by Microsoft and included as part of the Microsoft Windows line of operating systems starting in 1995....
.

JSON
JSON

JSON , short for JavaScript Object Notation, is a lightweight computer data interchange format. It is a text-based, human-readable format for representing simple data structures and associative arrays ....
, or JavaScript Object Notation, is a general-purpose data interchange format that is defined as a subset of JavaScript.

JavaScript is also considered a functional programming
Functional programming

In computer science, functional programming is a programming paradigm that treats computation as the evaluation of function s and avoids program state and immutable object data....
 language like Scheme and OCaml because it has closures
Closure (computer science)

In computer science, a closure is a function that is evaluated in an environment containing one or more bound variables. When called, the function can access these variables....
 and supports higher-order function
Higher-order function

In mathematics and computer science, higher-order functions or functional are function s which do at least one of the following:*take one or more functions as an input...
s.

Although JavaScript and Lua are not genealogically related, the two are semantically very similar despite apparent syntactical and implementational differences.

Mozilla browsers currently support LiveConnect
LiveConnect

LiveConnect is a feature of Web browsers that allows Java and JavaScript software to intercommunicate within a Web page. From the Java side it allows an applet to invoke the embedded scripts of a page or to access the built-in JavaScript environment, much as scripts can....
, a feature that allows JavaScript and Java to intercommunicate on the web. However, support for LiveConnect is scheduled to be phased out in the future.

JavaScript and Java

A common misconception is that JavaScript is similar or closely related to Java
Java (programming language)

Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java ....
; this is not so. Both have a C-like syntax, are object-oriented, are typically sandboxed and are widely used in client-side Web applications, but the similarities end there. Java has static typing; JavaScript's typing is dynamic (meaning a variable can hold an object of any type and cannot be restricted). Java is loaded from compiled bytecode; JavaScript is loaded as human-readable code. C is their last common ancestor language.

Nonetheless, JavaScript was designed with Java's syntax and standard library in mind. In particular, all Java keywords are reserved in JavaScript, JavaScript's standard library follows Java's naming conventions, and JavaScript's Math and Date classes are based on those from Java 1.0.

See also


Bibliography


External links

  • Mozilla Developer Center
    • References for Core JavaScript versions:
    • New in JavaScript: , ,
    • List of JavaScript releases: versions