[Previous] [Next] [First] [Last]


JavaScript is a general-purpose, prototype-based, object-oriented scripting language. It is designed to be embedded in diverse applications and systems, without consuming much memory. JavaScript borrows most of its syntax from Java, but also inherits from Awk and Perl, with some indirect influence from Self in its object prototype system.

JavaScript is dynamically typed, that is, programs do not declare variable types, and the type of a variable is unrestricted and can change at runtime. Source code can be generated at runtime and evaluated against an arbitrary scope. Typical implementations compile by translating source into an unspecified bytecode format, to check syntax and source consistency. Note that the ability to generate and interpret programs at runtime implies the presence of a compiler at runtime.

JavaScript is a high-level scripting language that does not depend on or expose particular machine representations or operating system services. It provides automatic storage management, typically using a garbage collector. The language and the standard objects and functions documented in this specification provide no unsafe access to memory or other hardware resources.

1.1 Implementation Versions

JavaScript version 1.0 was implemented in Netscape Navigator 2.0 and Netscape LiveWire 1.0. This specification describes JavaScript version 1.1, which was implemented in Netscape Navigator 3.0. This specification describes the language and its standard objects and functions, but not the objects and functions peculiar to a particular implementation. Where possible, bugs in the implementation of version 1.1 are identified as deviations from the specification.

Although JavaScript was originally implemented as a scripting language for HTML in Netscape Navigator and LiveWire, this specification does not prescribe any particular application.

1.2 Grammar Notation

Terminal symbols are shown in fixed width font in the productions of the lexical and syntactic grammars, and throughout this specification whenever the text is directly referring to such a terminal symbol. These are to appear in a program exactly as written.

Nonterminal symbols are shown in italic fixed width font. The definition of a nonterminal is introduced by the name of the nonterminal followed by a colon. One or more alternative right-hand sides for the nonterminal then follow on succeeding lines. For example, the syntactic definition:

          if ( Expression ) Statement

states that the nonterminal IfThenStatement represents the token if, followed by a left parenthesis token, followed by an Expression, followed by a right parenthesis token, followed by a Statement. As another example, the syntactic definition:

          ArgumentList , Argument

states that an ArgumentList may represent either a single Argument or an ArgumentList, followed by a comma, followed by an Argument. This definition of ArgumentList is recursive, that is to say, it is defined in terms of itself. The result is that an ArgumentList may contain any positive number of arguments. Such recursive definitions of nonterminals are common.

The informal grammar in this specification is bottom-up and left-recursive. A complete top-down, right-recursive grammar with disambiguation rules is included in an appendix.

The subscripted suffix opt, which may appear after a terminal or nonterminal, indicates an optional symbol. The alternative containing the optional symbol actually specifies two right-hand sides, one that omits the optional element and one that includes it. So, for example:

          return Expressionopt 

is an abbreviation for:

          return Expression

When the words "one of" follow the colon in a grammar definition, they signify that each of the terminal symbols or tokens on the following line or lines is an alternative definition. For example:

OctalDigit: one of
          0 1 2 3 4 5 6 7

which is a convenient abbreviation for:


The right-hand side of a lexical production may indicate that certain expansions are not permitted by using the phrase "but not" and then naming the excluded expansions, as in the productions for Identifier:

          IdentifierName, but not a Keyword or BooleanLiteral or NullLiteral

Finally, a few nonterminal symbols are described by a descriptive phrase where it would be impractical to list all the alternatives, for example:

          any ASCII character

1.3 Example Programs

The example programs given in the text are ready to be executed by a JavaScript system. Since this specification does not describe any specific mechanism for JavaScript to display output, examples suppose a simple println function that displays values to the user. In Netscape Navigator, this function would be defined as follows:

function println(x) {
          document.write(x, "<BR>")

This function is intended for illustrative and pedagogical purposes only, and is not part of the language specification.

1.4 References

Bobrow, Daniel G., Linda G. Demichiel, Richard P. Gabriel, Sonya E. Keene, Gregor Kiczales, and David A. Moon. Common Lisp Object System Specification, X3J13 Document 88-002R, June 1988; appears as Chapter 28 of Steele, Guy. Common Lisp: The Language, 2nd ed. Digital Press, 1990, ISBN 1-55558-041-6, 770-864.

IEEE Standard for Binary Floating-Point Arithmetic. ANSI/IEEE Std. 754-1985. Available from Global Engineering Documents, 15 Inverness Way East, Englewood, Colorado 80112-5704 USA; 800-854-7179.

Kernighan, Brian W., and Dennis M. Ritchie. The C Programming Language, 2nd ed. Prentice Hall, Englewood Cliffs, New Jersey, 1988, ISBN 0-13-110362-8.

Gosling, James, Bill Joy, and Guy Steele. The Java Language Specification. Addison Wesley Publishing Company, 1996

Agesen, et. al. The Self 3.0 Programmer's Reference Manual. Sun Microsystems, 1993, Mountain View, California.

Stroustrup, Bjarne. The C++ Progamming Language, 2nd ed. Addison-Wesley, Reading, Massachusetts, 1991, reprinted with corrections January 1994, ISBN 0-201-53992-6.

[Previous] [Next] [First] [Last]