Standard ECMA-262 5.1 Edition / June 2011 ECMAScript® Language Specification

This is the HTML rendering of Ecma-262 Edition 5.1, The ECMAScript Language Specification. The PDF rendering of this document is located at http://www.ecma-international.org/ecma-262/5.1/ECMA-262.pdf. The PDF version is the definitive specification. Any discrepancies between this HTML version and the PDF version are unintentional.

Copyright notice Copyright © 2011 Ecma International Ecma International

Rue du Rhone 114

CH-1204 Geneva

Tel: +41 22 849 6000

Fax: +41 22 849 6001

Web: http://www.ecma-international.org This document and possible translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published, and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and this section are included on all such copies and derivative works. However, this document itself may not be modified in any way, including by removing the copyright notice or references to Ecma International, except as needed for the purpose of developing any document or deliverable produced by Ecma International (in which case the rules applied to copyrights must be followed) or as required to translate it into languages other than English. The limited permissions granted above are perpetual and will not be revoked by Ecma International or its successors or assigns. This document and the information contained herein is provided on an "AS IS" basis and ECMA INTERNATIONAL DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY OWNERSHIP RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE." Software License All Software contained in this document ("Software)" is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT http://www.ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS*. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Introduction This Ecma Standard is based on several originating technologies, the most well known being JavaScript (Netscape) and JScript (Microsoft). The language was invented by Brendan Eich at Netscape and first appeared in that company’s Navigator 2.0 browser. It has appeared in all subsequent browsers from Netscape and in all browsers from Microsoft starting with Internet Explorer 3.0. The development of this Standard started in November 1996. The first edition of this Ecma Standard was adopted by the Ecma General Assembly of June 1997. That Ecma Standard was submitted to ISO/IEC JTC 1 for adoption under the fast-track procedure, and approved as international standard ISO/IEC 16262, in April 1998. The Ecma General Assembly of June 1998 approved the second edition of ECMA-262 to keep it fully aligned with ISO/IEC 16262. Changes between the first and the second edition are editorial in nature. The third edition of the Standard introduced powerful regular expressions, better string handling, new control statements, try/catch exception handling, tighter definition of errors, formatting for numeric output and minor changes in anticipation of forthcoming internationalisation facilities and future language growth. The third edition of the ECMAScript standard was adopted by the Ecma General Assembly of December 1999 and published as ISO/IEC 16262:2002 in June 2002. Since publication of the third edition, ECMAScript has achieved massive adoption in conjunction with the World Wide Web where it has become the programming language that is supported by essentially all web browsers. Significant work was done to develop a fourth edition of ECMAScript. Although that work was not completed and not published as the fourth edition of ECMAScript, it informs continuing evolution of the language. The fifth edition of ECMAScript (published as ECMA-262 5th edition) codifies de facto interpretations of the language specification that have become common among browser implementations and adds support for new features that have emerged since the publication of the third edition. Such features include accessor properties, reflective creation and inspection of objects, program control of property attributes, additional array manipulation functions, support for the JSON object encoding format, and a strict mode that provides enhanced error checking and program security. This present edition 5.1 of the ECMAScript Standard is fully aligned with third edition of the international standard ISO/IEC 16262:2011. ECMAScript is a vibrant language and the evolution of the language is not complete. Significant technical enhancement will continue with future editions of this specification. This Ecma Standard has been adopted by the General Assembly of June 2011.

ECMAScript Language Specification

1 This Standard defines the ECMAScript scripting language.

2 A conforming implementation of ECMAScript must provide and support all the types, values, objects, properties, functions, and program syntax and semantics described in this specification. A conforming implementation of this Standard shall interpret characters in conformance with the Unicode Standard, Version 3.0 or later and ISO/IEC 10646-1 with either UCS-2 or UTF-16 as the adopted encoding form, implementation level 3. If the adopted ISO/IEC 10646-1 subset is not otherwise specified, it is presumed to be the BMP subset, collection 300. If the adopted encoding form is not otherwise specified, it presumed to be the UTF-16 encoding form. A conforming implementation of ECMAScript is permitted to provide additional types, values, objects, properties, and functions beyond those described in this specification. In particular, a conforming implementation of ECMAScript is permitted to provide properties not described in this specification, and values for those properties, for objects that are described in this specification. A conforming implementation of ECMAScript is permitted to support program and regular expression syntax not described in this specification. In particular, a conforming implementation of ECMAScript is permitted to support program syntax that makes use of the “future reserved words” listed in 7.6.1.2 of this specification.

3 The following referenced documents are indispensable for the application of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies. ISO/IEC 9899:1996, Programming Languages – C, including amendment 1 and technical corrigenda 1 and 2 ISO/IEC 10646-1:1993, Information Technology – Universal Multiple-Octet Coded Character Set (UCS) plus its amendments and corrigenda

4 This section contains a non-normative overview of the ECMAScript language. ECMAScript is an object-oriented programming language for performing computations and manipulating computational objects within a host environment. ECMAScript as defined here is not intended to be computationally self-sufficient; indeed, there are no provisions in this specification for input of external data or output of computed results. Instead, it is expected that the computational environment of an ECMAScript program will provide not only the objects and other facilities described in this specification but also certain environment-specific host objects, whose description and behaviour are beyond the scope of this specification except to indicate that they may provide certain properties that can be accessed and certain functions that can be called from an ECMAScript program. A scripting language is a programming language that is used to manipulate, customise, and automate the facilities of an existing system. In such systems, useful functionality is already available through a user interface, and the scripting language is a mechanism for exposing that functionality to program control. In this way, the existing system is said to provide a host environment of objects and facilities, which completes the capabilities of the scripting language. A scripting language is intended for use by both professional and non-professional programmers. ECMAScript was originally designed to be a Web scripting language, providing a mechanism to enliven Web pages in browsers and to perform server computation as part of a Web-based client-server architecture. ECMAScript can provide core scripting capabilities for a variety of host environments, and therefore the core scripting language is specified in this document apart from any particular host environment. Some of the facilities of ECMAScript are similar to those used in other programming languages; in particular Java™, Self, and Scheme as described in: Gosling, James, Bill Joy and Guy Steele. The Java™ Language Specification. Addison Wesley Publishing Co., 1996. Ungar, David, and Smith, Randall B. Self: The Power of Simplicity. OOPSLA '87 Conference Proceedings, pp. 227–241, Orlando, FL, October 1987. IEEE Standard for the Scheme Programming Language. IEEE Std 1178-1990. 4.1 A web browser provides an ECMAScript host environment for client-side computation including, for instance, objects that represent windows, menus, pop-ups, dialog boxes, text areas, anchors, frames, history, cookies, and input/output. Further, the host environment provides a means to attach scripting code to events such as change of focus, page and image loading, unloading, error and abort, selection, form submission, and mouse actions. Scripting code appears within the HTML and the displayed page is a combination of user interface elements and fixed and computed text and images. The scripting code is reactive to user interaction and there is no need for a main program. A web server provides a different host environment for server-side computation including objects representing requests, clients, and files; and mechanisms to lock and share data. By using browser-side and server-side scripting together, it is possible to distribute computation between the client and server while providing a customised user interface for a Web-based application. Each Web browser and server that supports ECMAScript supplies its own host environment, completing the ECMAScript execution environment. 4.2 The following is an informal overview of ECMAScript—not all parts of the language are described. This overview is not part of the standard proper. ECMAScript is object-based: basic language and host facilities are provided by objects, and an ECMAScript program is a cluster of communicating objects. An ECMAScript object is a collection of properties each with zero or more attributes that determine how each property can be used—for example, when the Writable attribute for a property is set to false, any attempt by executed ECMAScript code to change the value of the property fails. Properties are containers that hold other objects, primitive values, or functions. A primitive value is a member of one of the following built-in types: Undefined, Null, Boolean, Number, and String; an object is a member of the remaining built-in type Object; and a function is a callable object. A function that is associated with an object via a property is a method. ECMAScript defines a collection of built-in objects that round out the definition of ECMAScript entities. These built-in objects include the global object, the Object object, the Function object, the Array object, the String object, the Boolean object, the Number object, the Math object, the Date object, the RegExp object, the JSON object, and the Error objects Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError and URIError. ECMAScript also defines a set of built-in operators. ECMAScript operators include various unary operations, multiplicative operators, additive operators, bitwise shift operators, relational operators, equality operators, binary bitwise operators, binary logical operators, assignment operators, and the comma operator. ECMAScript syntax intentionally resembles Java syntax. ECMAScript syntax is relaxed to enable it to serve as an easy-to-use scripting language. For example, a variable is not required to have its type declared nor are types associated with properties, and defined functions are not required to have their declarations appear textually before calls to them. 4.2.1 ECMAScript does not use classes such as those in C++, Smalltalk, or Java. Instead objects may be created in various ways including via a literal notation or via constructors which create objects and then execute code that initialises all or part of them by assigning initial values to their properties. Each constructor is a function that has a property named “ prototype ” that is used to implement prototype-based inheritance and shared properties. Objects are created by using constructors in new expressions; for example, new Date(2009,11) creates a new Date object. Invoking a constructor without using new has consequences that depend on the constructor. For example, Date() produces a string representation of the current date and time rather than an object. Every object created by a constructor has an implicit reference (called the object’s prototype) to the value of its constructor’s “ prototype ” property. Furthermore, a prototype may have a non-null implicit reference to its prototype, and so on; this is called the prototype chain. When a reference is made to a property in an object, that reference is to the property of that name in the first object in the prototype chain that contains a property of that name. In other words, first the object mentioned directly is examined for such a property; if that object contains the named property, that is the property to which the reference refers; if that object does not contain the named property, the prototype for that object is examined next; and so on. Figure 1 — Object/Prototype Relationships In a class-based object-oriented language, in general, state is carried by instances, methods are carried by classes, and inheritance is only of structure and behaviour. In ECMAScript, the state and methods are carried by objects, and structure, behaviour, and state are all inherited. All objects that do not directly contain a particular property that their prototype contains share that property and its value. Figure 1 illustrates this: CF is a constructor (and also an object). Five objects have been created by using new expressions: cf 1 , cf 2 , cf 3 , cf 4 , and cf 5 . Each of these objects contains properties named q1 and q2. The dashed lines represent the implicit prototype relationship; so, for example, cf 3 ’s prototype is CF p . The constructor, CF, has two properties itself, named P1 and P2, which are not visible to CF p , cf 1 , cf 2 , cf 3 , cf 4 , or cf 5 . The property named CFP1 in CF p is shared by cf 1 , cf 2 , cf 3 , cf 4 , and cf 5 (but not by CF), as are any properties found in CF p ’s implicit prototype chain that are not named q1, q2, or CFP1. Notice that there is no implicit prototype link between CF and CF p . Unlike class-based object languages, properties can be added to objects dynamically by assigning values to them. That is, constructors are not required to name or assign values to all or any of the constructed object’s properties. In the above diagram, one could add a new shared property for cf 1 , cf 2 , cf 3 , cf 4 , and cf 5 by assigning a new value to the property in CF p . 4.2.2 The ECMAScript Language recognises the possibility that some users of the language may wish to restrict their usage of some features available in the language. They might do so in the interests of security, to avoid what they consider to be error-prone features, to get enhanced error checking, or for other reasons of their choosing. In support of this possibility, ECMAScript defines a strict variant of the language. The strict variant of the language excludes some specific syntactic and semantic features of the regular ECMAScript language and modifies the detailed semantics of some features. The strict variant also specifies additional error conditions that must be reported by throwing error exceptions in situations that are not specified as errors by the non-strict form of the language. The strict variant of ECMAScript is commonly referred to as the strict mode of the language. Strict mode selection and use of the strict mode syntax and semantics of ECMAScript is explicitly made at the level of individual ECMAScript code units. Because strict mode is selected at the level of a syntactic code unit, strict mode only imposes restrictions that have local effect within such a code unit. Strict mode does not restrict or modify any aspect of the ECMAScript semantics that must operate consistently across multiple code units. A complete ECMAScript program may be composed for both strict mode and non-strict mode ECMAScript code units. In this case, strict mode only applies when actually executing code that is defined within a strict mode code unit. In order to conform to this specification, an ECMAScript implementation must implement both the full unrestricted ECMAScript language and the strict mode variant of the ECMAScript language as defined by this specification. In addition, an implementation must support the combination of unrestricted and strict mode code units into a single composite program. 4.3 For the purposes of this document, the following terms and definitions apply. 4.3.1 set of data values as defined in Clause 8 of this specification 4.3.2 member of one of the types Undefined, Null, Boolean, Number, or String as defined in Clause 8 NOTE A primitive value is a datum that is represented directly at the lowest level of the language implementation. 4.3.3 member of the type Object NOTE An object is a collection of properties and has a single prototype object. The prototype may be the null value. 4.3.4 function object that creates and initialises objects NOTE The value of a constructor’s “prototype” property is a prototype object that is used to implement inheritance and shared properties. 4.3.5 object that provides shared properties for other objects NOTE When a constructor creates an object, that object implicitly references the constructor’s “ prototype ” property for the purpose of resolving property references. The constructor’s “ prototype ” property can be referenced by the program expression constructor.prototype, and properties added to an object’s prototype are shared, through inheritance, by all objects sharing the prototype. Alternatively, a new object may be created with an explicitly specified prototype by using the Object.create built-in function. 4.3.6 object in an ECMAScript implementation whose semantics are fully defined by this specification rather than by the host environment NOTE Standard native objects are defined in this specification. Some native objects are built-in; others may be constructed during the course of execution of an ECMAScript program. 4.3.7 object supplied by an ECMAScript implementation, independent of the host environment, that is present at the start of the execution of an ECMAScript program NOTE Standard built-in objects are defined in this specification, and an ECMAScript implementation may specify and define others. Every built-in object is a native object. A built-in constructor is a built-in object that is also a constructor. 4.3.8 object supplied by the host environment to complete the execution environment of ECMAScript NOTE Any object that is not native is a host object. 4.3.9 primitive value used when a variable has not been assigned a value 4.3.10 type whose sole value is the undefined value 4.3.11 primitive value that represents the intentional absence of any object value 4.3.12 type whose sole value is the null value 4.3.13 member of the Boolean type NOTE There are only two Boolean values, true and false. 4.3.14 type consisting of the primitive values true and false 4.3.15 member of the Object type that is an instance of the standard built-in Boolean constructor NOTE A Boolean object is created by using the Boolean constructor in a new expression, supplying a Boolean value as an argument. The resulting object has an internal property whose value is the Boolean value. A Boolean object can be coerced to a Boolean value. 4.3.16 primitive value that is a finite ordered sequence of zero or more 16-bit unsigned integer NOTE A String value is a member of the String type. Each integer value in the sequence usually represents a single 16-bit unit of UTF-16 text. However, ECMAScript does not place any restrictions or requirements on the values except that they must be 16-bit unsigned integers. 4.3.17 set of all possible String values 4.3.18 member of the Object type that is an instance of the standard built-in String constructor NOTE A String object is created by using the String constructor in a new expression, supplying a String value as an argument. The resulting object has an internal property whose value is the String value. A String object can be coerced to a String value by calling the String constructor as a function (15.5.1). 4.3.19 primitive value corresponding to a double-precision 64-bit binary format IEEE 754 value NOTE A Number value is a member of the Number type and is a direct representation of a number. 4.3.20 set of all possible Number values including the special “Not-a-Number” (NaN) values, positive infinity, and negative infinity 4.3.21 member of the Object type that is an instance of the standard built-in Number constructor NOTE A Number object is created by using the Number constructor in a new expression, supplying a Number value as an argument. The resulting object has an internal property whose value is the Number value. A Number object can be coerced to a Number value by calling the Number constructor as a function (15.7.1). 4.3.22 number value that is the positive infinite Number value 4.3.23 number value that is a IEEE 754 “Not-a-Number” value 4.3.24 member of the Object type that is an instance of the standard built-in Function constructor and that may be invoked as a subroutine NOTE In addition to its named properties, a function contains executable code and state that determine how it behaves when invoked. A function’s code may or may not be written in ECMAScript. 4.3.25 built-in object that is a function NOTE Examples of built-in functions include parseInt and Math.exp . An implementation may provide implementation-dependent built-in functions that are not described in this specification. 4.3.26 association between a name and a value that is a part of an object NOTE Depending upon the form of the property the value may be represented either directly as a data value (a primitive value, an object, or a function object) or indirectly by a pair of accessor functions. 4.3.27 function that is the value of a property NOTE When a function is called as a method of an object, the object is passed to the function as its this value. 4.3.28 method that is a built-in function NOTE Standard built-in methods are defined in this specification, and an ECMAScript implementation may specify and provide other additional built-in methods. 4.3.29 internal value that defines some characteristic of a property 4.3.30 property that is directly contained by its object 4.3.31 property of an object that is not an own property but is a property (either own or inherited) of the object’s prototype

5 5.1 5.1.1 A context-free grammar consists of a number of productions. Each production has an abstract symbol called a nonterminal as its left-hand side, and a sequence of zero or more nonterminal and terminal symbols as its right-hand side. For each grammar, the terminal symbols are drawn from a specified alphabet. Starting from a sentence consisting of a single distinguished nonterminal, called the goal symbol, a given context-free grammar specifies a language, namely, the (perhaps infinite) set of possible sequences of terminal symbols that can result from repeatedly replacing any nonterminal in the sequence with a right-hand side of a production for which the nonterminal is the left-hand side. 5.1.2 A lexical grammar for ECMAScript is given in clause 7. This grammar has as its terminal symbols characters (Unicode code units) that conform to the rules for SourceCharacter defined in Clause 6. It defines a set of productions, starting from the goal symbol InputElementDiv or InputElementRegExp, that describe how sequences of such characters are translated into a sequence of input elements. Input elements other than white space and comments form the terminal symbols for the syntactic grammar for ECMAScript and are called ECMAScript tokens. These tokens are the reserved words, identifiers, literals, and punctuators of the ECMAScript language. Moreover, line terminators, although not considered to be tokens, also become part of the stream of input elements and guide the process of automatic semicolon insertion (7.9). Simple white space and single-line comments are discarded and do not appear in the stream of input elements for the syntactic grammar. A MultiLineComment (that is, a comment of the form “/*…*/” regardless of whether it spans more than one line) is likewise simply discarded if it contains no line terminator; but if a MultiLineComment contains one or more line terminators, then it is replaced by a single line terminator, which becomes part of the stream of input elements for the syntactic grammar. A RegExp grammar for ECMAScript is given in 15.10. This grammar also has as its terminal symbols the characters as defined by SourceCharacter. It defines a set of productions, starting from the goal symbol Pattern, that describe how sequences of characters are translated into regular expression patterns. Productions of the lexical and RegExp grammars are distinguished by having two colons “::” as separating punctuation. The lexical and RegExp grammars share some productions. 5.1.3 Another grammar is used for translating Strings into numeric values. This grammar is similar to the part of the lexical grammar having to do with numeric literals and has as its terminal symbols SourceCharacter. This grammar appears in 9.3.1. Productions of the numeric string grammar are distinguished by having three colons “:::” as punctuation. 5.1.4 The syntactic grammar for ECMAScript is given in clauses 11, 12, 13 and 14. This grammar has ECMAScript tokens defined by the lexical grammar as its terminal symbols (5.1.2). It defines a set of productions, starting from the goal symbol Program, that describe how sequences of tokens can form syntactically correct ECMAScript programs. When a stream of characters is to be parsed as an ECMAScript program, it is first converted to a stream of input elements by repeated application of the lexical grammar; this stream of input elements is then parsed by a single application of the syntactic grammar. The program is syntactically in error if the tokens in the stream of input elements cannot be parsed as a single instance of the goal nonterminal Program, with no tokens left over. Productions of the syntactic grammar are distinguished by having just one colon “:” as punctuation. The syntactic grammar as presented in clauses 11, 12, 13 and 14 is actually not a complete account of which token sequences are accepted as correct ECMAScript programs. Certain additional token sequences are also accepted, namely, those that would be described by the grammar if only semicolons were added to the sequence in certain places (such as before line terminator characters). Furthermore, certain token sequences that are described by the grammar are not considered acceptable if a terminator character appears in certain “awkward” places. 5.1.5 The JSON grammar is used to translate a String describing a set of ECMAScript objects into actual objects. The JSON grammar is given in 15.12.1. The JSON grammar consists of the JSON lexical grammar and the JSON syntactic grammar. The JSON lexical grammar is used to translate character sequences into tokens and is similar to parts of the ECMAScript lexical grammar. The JSON syntactic grammar describes how sequences of tokens from the JSON lexical grammar can form syntactically correct JSON object descriptions. Productions of the JSON lexical grammar are distinguished by having two colons “::” as separating punctuation. The JSON lexical grammar uses some productions from the ECMAScript lexical grammar. The JSON syntactic grammar is similar to parts of the ECMAScript syntactic grammar. Productions of the JSON syntactic grammar are distinguished by using one colon “:” as separating punctuation. 5.1.6 Terminal symbols of the lexical, RegExp, and numeric string grammars, and some of the terminal symbols of the other grammars, are shown in fixed width font, both in the productions of the grammars and throughout this specification whenever the text directly refers to such a terminal symbol. These are to appear in a program exactly as written. All terminal symbol characters specified in this way are to be understood as the appropriate Unicode character from the ASCII range, as opposed to any similar-looking characters from other Unicode ranges. Nonterminal symbols are shown in italic type. The definition of a nonterminal is introduced by the name of the nonterminal being defined followed by one or more colons. (The number of colons indicates to which grammar the production belongs.) One or more alternative right-hand sides for the nonterminal then follow on succeeding lines. For example, the syntactic definition: WhileStatement : while ( Expression ) Statement states that the nonterminal WhileStatement represents the token while , followed by a left parenthesis token, followed by an Expression, followed by a right parenthesis token, followed by a Statement. The occurrences of Expression and Statement are themselves nonterminals. As another example, the syntactic definition: ArgumentList : AssignmentExpression ArgumentList , AssignmentExpression states that an ArgumentList may represent either a single AssignmentExpression or an ArgumentList, followed by a comma, followed by an AssignmentExpression. This definition of ArgumentList is recursive, that is, it is defined in terms of itself. The result is that an ArgumentList may contain any positive number of arguments, separated by commas, where each argument expression is an AssignmentExpression. Such recursive definitions of nonterminals are common. 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. This means that: VariableDeclaration : Identifier Initialiser opt is a convenient abbreviation for: VariableDeclaration : Identifier Identifier Initialiser and that: IterationStatement : for ( ExpressionNoIn opt ; Expression opt ; Expression opt ) Statement is a convenient abbreviation for: IterationStatement : for ( ; Expression opt ; Expression opt ) Statement for ( ExpressionNoIn ; Expression opt ; Expression opt ) Statement which in turn is an abbreviation for: IterationStatement : for ( ; ; Expression opt ) Statement for ( ; Expression ; Expression opt ) Statement for ( ExpressionNoIn ; ; Expression opt ) Statement for ( ExpressionNoIn ; Expression ; Expression opt ) Statement which in turn is an abbreviation for: IterationStatement : for ( ; ; ) Statement for ( ; ; Expression ) Statement for ( ; Expression ; ) Statement for ( ; Expression ; Expression ) Statement for ( ExpressionNoIn ; ; ) Statement for ( ExpressionNoIn ; ; Expression ) Statement for ( ExpressionNoIn ; Expression ; ) Statement for ( ExpressionNoIn ; Expression ; Expression ) Statement so the nonterminal IterationStatement actually has eight alternative right-hand sides. When the words “one of” follow the colon(s) in a grammar definition, they signify that each of the terminal symbols on the following line or lines is an alternative definition. For example, the lexical grammar for ECMAScript contains the production: NonZeroDigit :: one of 1 2 3 4 5 6 7 8 9 which is merely a convenient abbreviation for: NonZeroDigit :: 1 2 3 4 5 6 7 8 9 If the phrase “[empty]” appears as the right-hand side of a production, it indicates that the production's right-hand side contains no terminals or nonterminals. If the phrase “[lookahead ∉ set ]” appears in the right-hand side of a production, it indicates that the production may not be used if the immediately following input token is a member of the given set . The set can be written as a list of terminals enclosed in curly braces. For convenience, the set can also be written as a nonterminal, in which case it represents the set of all terminals to which that nonterminal could expand. For example, given the definitions DecimalDigit :: one of 0 1 2 3 4 5 6 7 8 9 DecimalDigits :: DecimalDigit DecimalDigits DecimalDigit the definition LookaheadExample :: n [lookahead ∉ { 1 , 3 , 5 , 7 , 9 }] DecimalDigits DecimalDigit [lookahead ∉ DecimalDigit ] matches either the letter n followed by one or more decimal digits the first of which is even, or a decimal digit not followed by another decimal digit. If the phrase “[no LineTerminator here]” appears in the right-hand side of a production of the syntactic grammar, it indicates that the production is a restricted production: it may not be used if a LineTerminator occurs in the input stream at the indicated position. For example, the production: ThrowStatement : throw [no LineTerminator here] Expression ; indicates that the production may not be used if a LineTerminator occurs in the program between the throw token and the Expression. Unless the presence of a LineTerminator is forbidden by a restricted production, any number of occurrences of LineTerminator may appear between any two consecutive tokens in the stream of input elements without affecting the syntactic acceptability of the program. When an alternative in a production of the lexical grammar or the numeric string grammar appears to be a multi-character token, it represents the sequence of characters that would make up such a token. The right-hand side of a production may specify that certain expansions are not permitted by using the phrase “but not” and then indicating the expansions to be excluded. For example, the production: Identifier :: IdentifierName but not ReservedWord means that the nonterminal Identifier may be replaced by any sequence of characters that could replace IdentifierName provided that the same sequence of characters could not replace ReservedWord. Finally, a few nonterminal symbols are described by a descriptive phrase in sans-serif type in cases where it would be impractical to list all the alternatives: SourceCharacter :: any Unicode code unit 5.2 The specification often uses a numbered list to specify steps in an algorithm. These algorithms are used to precisely specify the required semantics of ECMAScript language constructs. The algorithms are not intended to imply the use of any specific implementation technique. In practice, there may be more efficient algorithms available to implement a given feature. In order to facilitate their use in multiple parts of this specification, some algorithms, called abstract operations, are named and written in parameterised functional form so that they may be referenced by name from within other algorithms. When an algorithm is to produce a value as a result, the directive “return x” is used to indicate that the result of the algorithm is the value of x and that the algorithm should terminate. The notation Result(n) is used as shorthand for “the result of step n”. For clarity of expression, algorithm steps may be subdivided into sequential substeps. Substeps are indented and may themselves be further divided into indented substeps. Outline numbering conventions are used to identify substeps with the first level of substeps labelled with lower case alphabetic characters and the second level of substeps labelled with lower case roman numerals. If more than three levels are required these rules repeat with the fourth level using numeric labels. For example: Top-level step Substep. Substep Subsubstep. Subsubstep. Subsubsubstep Subsubsubsubstep A step or substep may be written as an “if” predicate that conditions its substeps. In this case, the substeps are only applied if the predicate is true. If a step or substep begins with the word “else”, it is a predicate that is the negation of the preceding “if” predicate step at the same level. A step may specify the iterative application of its substeps. A step may assert an invariant condition of its algorithm. Such assertions are used to make explicit algorithmic invariants that would otherwise be implicit. Such assertions add no additional semantic requirements and hence need not be checked by an implementation. They are used simply to clarify algorithms. Mathematical operations such as addition, subtraction, negation, multiplication, division, and the mathematical functions defined later in this clause should always be understood as computing exact mathematical results on mathematical real numbers, which do not include infinities and do not include a negative zero that is distinguished from positive zero. Algorithms in this standard that model floating-point arithmetic include explicit steps, where necessary, to handle infinities and signed zero and to perform rounding. If a mathematical operation or function is applied to a floating-point number, it should be understood as being applied to the exact mathematical value represented by that floating-point number; such a floating-point number must be finite, and if it is +0 or −0 then the corresponding mathematical value is simply 0. The mathematical function abs(x) yields the absolute value of x , which is −x if x is negative (less than zero) and otherwise is x itself. The mathematical function sign(x) yields 1 if x is positive and −1 if x is negative. The sign function is not used in this standard for cases when x is zero. The notation “x modulo y” ( y must be finite and nonzero) computes a value k of the same sign as y (or zero) such that abs(k) < abs(y) and x−k = q × y for some integer q . The mathematical function floor(x) yields the largest integer (closest to positive infinity) that is not larger than x . NOTE floor(x) = x−(x modulo 1). If an algorithm is defined to “throw an exception”, execution of the algorithm is terminated and no result is returned. The calling algorithms are also terminated, until an algorithm step is reached that explicitly deals with the exception, using terminology such as “If an exception was thrown…”. Once such an algorithm step has been encountered the exception is no longer considered to have occurred.

6 ECMAScript source text is represented as a sequence of characters in the Unicode character encoding, version 3.0 or later. The text is expected to have been normalised to Unicode Normalization Form C (canonical composition), as described in Unicode Technical Report #15. Conforming ECMAScript implementations are not required to perform any normalisation of text, or behave as though they were performing normalisation of text, themselves. ECMAScript source text is assumed to be a sequence of 16-bit code units for the purposes of this specification. Such a source text may include sequences of 16-bit code units that are not valid UTF-16 character encodings. If an actual source text is encoded in a form other than 16-bit code units it must be processed as if it was first converted to UTF-16. Syntax SourceCharacter :: any Unicode code unit Throughout the rest of this document, the phrase “code unit” and the word “character” will be used to refer to a 16-bit unsigned value used to represent a single 16-bit unit of text. The phrase “Unicode character” will be used to refer to the abstract linguistic or typographical unit represented by a single Unicode scalar value (which may be longer than 16 bits and thus may be represented by more than one code unit). The phrase “code point” refers to such a Unicode scalar value. “Unicode character” only refers to entities represented by single Unicode scalar values: the components of a combining character sequence are still individual “Unicode characters,” even though a user might think of the whole sequence as a single character. In string literals, regular expression literals, and identifiers, any character (code unit) may also be expressed as a Unicode escape sequence consisting of six characters, namely \u plus four hexadecimal digits. Within a comment, such an escape sequence is effectively ignored as part of the comment. Within a string literal or regular expression literal, the Unicode escape sequence contributes one character to the value of the literal. Within an identifier, the escape sequence contributes one character to the identifier. NOTE Although this document sometimes refers to a “transformation” between a “character” within a “string” and the 16-bit unsigned integer that is the code unit of that character, there is actually no transformation because a “character” within a “string” is actually represented using that 16-bit unsigned value. ECMAScript differs from the Java programming language in the behaviour of Unicode escape sequences. In a Java program, if the Unicode escape sequence \u000A , for example, occurs within a single-line comment, it is interpreted as a line terminator (Unicode character 000A is line feed) and therefore the next character is not part of the comment. Similarly, if the Unicode escape sequence \u000A occurs within a string literal in a Java program, it is likewise interpreted as a line terminator, which is not allowed within a string literal—one must write

instead of \u000A to cause a line feed to be part of the string value of a string literal. In an ECMAScript program, a Unicode escape sequence occurring within a comment is never interpreted and therefore cannot contribute to termination of the comment. Similarly, a Unicode escape sequence occurring within a string literal in an ECMAScript program always contributes a character to the String value of the literal and is never interpreted as a line terminator or as a quote mark that might terminate the string literal.

7 The source text of an ECMAScript program is first converted into a sequence of input elements, which are tokens, line terminators, comments, or white space. The source text is scanned from left to right, repeatedly taking the longest possible sequence of characters as the next input element. There are two goal symbols for the lexical grammar. The InputElementDiv symbol is used in those syntactic grammar contexts where a leading division ( / ) or division-assignment ( /= ) operator is permitted. The InputElementRegExp symbol is used in other syntactic grammar contexts. NOTE There are no syntactic grammar contexts where both a leading division or division-assignment, and a leading RegularExpressionLiteral are permitted. This is not affected by semicolon insertion (see 7.9); in examples such as the following: a = b

/hi/g.exec(c).map(d); where the first non-whitespace, non-comment character after a LineTerminator is slash ( / ) and the syntactic context allows division or division-assignment, no semicolon is inserted at the LineTerminator. That is, the above example is interpreted in the same way as: a = b / hi / g.exec(c).map(d); Syntax InputElementDiv :: WhiteSpace LineTerminator Comment Token DivPunctuator InputElementRegExp :: WhiteSpace LineTerminator Comment Token RegularExpressionLiteral 7.1 The Unicode format-control characters (i.e., the characters in category “Cf” in the Unicode Character Database such as left-to-right mark or right-to-left mark) are control codes used to control the formatting of a range of text in the absence of higher-level protocols for this (such as mark-up languages). It is useful to allow format-control characters in source text to facilitate editing and display. All format control characters may be used within comments, and within string literals and regular expression literals. <ZWNJ> and <ZWJ> are format-control characters that are used to make necessary distinctions when forming words or phrases in certain languages. In ECMAScript source text, <ZWNJ> and <ZWJ> may also be used in an identifier after the first character. <BOM> is a format-control character used primarily at the start of a text to mark it as Unicode and to allow detection of the text's encoding and byte order. <BOM> characters intended for this purpose can sometimes also appear after the start of a text, for example as a result of concatenating files. <BOM> characters are treated as white space characters (see 7.2). The special treatment of certain format-control characters outside of comments, string literals, and regular expression literals is summarised in Table 1. Table 1 — Format-Control Character Usage Code Unit Value Name Formal Name Usage \u200C Zero width non-joiner <ZWNJ> IdentifierPart \u200D Zero width joiner <ZWJ> IdentifierPart \uFEFF Byte Order Mark <BOM> Whitespace 7.2 White space characters are used to improve source text readability and to separate tokens (indivisible lexical units) from each other, but are otherwise insignificant. White space characters may occur between any two tokens and at the start or end of input. White space characters may also occur within a StringLiteral or a RegularExpressionLiteral (where they are considered significant characters forming part of the literal value) or within a Comment, but cannot appear within any other kind of token. The ECMAScript white space characters are listed in Table 2. Table 2 — Whitespace Characters Code Unit Value Name Formal Name \u0009 Tab <TAB> \u000B Vertical Tab <VT> \u000C Form Feed <FF> \u0020 Space <SP> \u00A0 No-break space <NBSP> \uFEFF Other category “Zs” Byte Order Mark Any other Unicode “space separator” <BOM> <USP> ECMAScript implementations must recognise all of the white space characters defined in Unicode 3.0. Later editions of the Unicode Standard may define other white space characters. ECMAScript implementations may recognise white space characters from later editions of the Unicode Standard. Syntax WhiteSpace :: <TAB> <VT> <FF> <SP> <NBSP> <BOM> <USP> 7.3 Like white space characters, line terminator characters are used to improve source text readability and to separate tokens (indivisible lexical units) from each other. However, unlike white space characters, line terminators have some influence over the behaviour of the syntactic grammar. In general, line terminators may occur between any two tokens, but there are a few places where they are forbidden by the syntactic grammar. Line terminators also affect the process of automatic semicolon insertion (7.9). A line terminator cannot occur within any token except a StringLiteral. Line terminators may only occur within a StringLiteral token as part of a LineContinuation. A line terminator can occur within a MultiLineComment (7.4) but cannot occur within a SingleLineComment. Line terminators are included in the set of white space characters that are matched by the \s class in regular expressions. The ECMAScript line terminator characters are listed in Table 3. Table 3 — Line Terminator Characters Code Unit Value Name Formal Name \u000A Line Feed <LF> \u000D Carriage Return <CR> \u2028 Line separator <LS> \u2029 Paragraph separator <PS> Only the characters in Table 3 are treated as line terminators. Other new line or line breaking characters are treated as white space but not as line terminators. The character sequence <CR><LF> is commonly used as a line terminator. It should be considered a single character for the purpose of reporting line numbers. Syntax LineTerminator :: <LF> <CR> <LS> <PS> LineTerminatorSequence :: <LF> <CR> [lookahead ∉ <LF> ] <LS> <PS> <CR> <LF> 7.4 Comments can be either single or multi-line. Multi-line comments cannot nest. Because a single-line comment can contain any character except a LineTerminator character, and because of the general rule that a token is always as long as possible, a single-line comment always consists of all characters from the // marker to the end of the line. However, the LineTerminator at the end of the line is not considered to be part of the single-line comment; it is recognised separately by the lexical grammar and becomes part of the stream of input elements for the syntactic grammar. This point is very important, because it implies that the presence or absence of single-line comments does not affect the process of automatic semicolon insertion (see 7.9). Comments behave like white space and are discarded except that, if a MultiLineComment contains a line terminator character, then the entire comment is considered to be a LineTerminator for purposes of parsing by the syntactic grammar. Syntax Comment :: MultiLineComment SingleLineComment MultiLineComment :: /* MultiLineCommentChars opt */ MultiLineCommentChars :: MultiLineNotAsteriskChar MultiLineCommentChars opt * PostAsteriskCommentChars opt PostAsteriskCommentChars :: MultiLineNotForwardSlashOrAsteriskChar MultiLineCommentChars opt * PostAsteriskCommentChars opt MultiLineNotAsteriskChar :: SourceCharacter but not * MultiLineNotForwardSlashOrAsteriskChar :: SourceCharacter but not one of / or * SingleLineComment :: // SingleLineCommentChars opt SingleLineCommentChars :: SingleLineCommentChar SingleLineCommentChars opt SingleLineCommentChar :: SourceCharacter but not LineTerminator 7.5 Syntax Token :: IdentifierName Punctuator NumericLiteral StringLiteral NOTE The DivPunctuator and RegularExpressionLiteral productions define tokens, but are not included in the Token production. 7.6 Identifier Names are tokens that are interpreted according to the grammar given in the “Identifiers” section of chapter 5 of the Unicode standard, with some small modifications. An Identifier is an IdentifierName that is not a ReservedWord (see 7.6.1). The Unicode identifier grammar is based on both normative and informative character categories specified by the Unicode Standard. The characters in the specified categories in version 3.0 of the Unicode standard must be treated as in those categories by all conforming ECMAScript implementations. This standard specifies specific character additions: The dollar sign ( $ ) and the underscore ( _ ) are permitted anywhere in an IdentifierName. Unicode escape sequences are also permitted in an IdentifierName, where they contribute a single character to the IdentifierName, as computed by the CV of the UnicodeEscapeSequence (see 7.8.4). The \ preceding the UnicodeEscapeSequence does not contribute a character to the IdentifierName. A UnicodeEscapeSequence cannot be used to put a character into an IdentifierName that would otherwise be illegal. In other words, if a \ UnicodeEscapeSequence sequence were replaced by its UnicodeEscapeSequence's CV, the result must still be a valid IdentifierName that has the exact same sequence of characters as the original IdentifierName. All interpretations of identifiers within this specification are based upon their actual characters regardless of whether or not an escape sequence was used to contribute any particular characters. Two IdentifierName that are canonically equivalent according to the Unicode standard are not equal unless they are represented by the exact same sequence of code units (in other words, conforming ECMAScript implementations are only required to do bitwise comparison on IdentifierName values). The intent is that the incoming source text has been converted to normalised form C before it reaches the compiler. ECMAScript implementations may recognise identifier characters defined in later editions of the Unicode Standard. If portability is a concern, programmers should only employ identifier characters defined in Unicode 3.0. Syntax Identifier :: IdentifierName but not ReservedWord IdentifierName :: IdentifierStart IdentifierName IdentifierPart IdentifierStart :: UnicodeLetter $ _ \ UnicodeEscapeSequence IdentifierPart :: IdentifierStart UnicodeCombiningMark UnicodeDigit UnicodeConnectorPunctuation <ZWNJ> <ZWJ> UnicodeLetter :: any character in the Unicode categories “Uppercase letter (Lu)”, “Lowercase letter (Ll)”, “Titlecase letter (Lt)”, “Modifier letter (Lm)”, “Other letter (Lo)”, or “Letter number (Nl)”. UnicodeCombiningMark :: any character in the Unicode categories “Non-spacing mark (Mn)” or “Combining spacing mark (Mc)” UnicodeDigit :: any character in the Unicode category “Decimal number (Nd)” UnicodeConnectorPunctuation :: any character in the Unicode category “Connector punctuation (Pc)” The definitions of the nonterminal UnicodeEscapeSequence is given in 7.8.4 7.6.1 A reserved word is an IdentifierName that cannot be used as an Identifier. Syntax ReservedWord :: Keyword FutureReservedWord NullLiteral BooleanLiteral 7.6.1.1 The following tokens are ECMAScript keywords and may not be used as Identifiers in ECMAScript programs. Syntax Keyword :: one of break do instanceof typeof case else new var catch finally return void continue for switch while debugger function this with default if throw delete in try 7.6.1.2 The following words are used as keywords in proposed extensions and are therefore reserved to allow for the possibility of future adoption of those extensions. Syntax FutureReservedWord :: one of class enum extends super const export import The following tokens are also considered to be FutureReservedWords when they occur within strict mode code (see 10.1.1). The occurrence of any of these tokens within strict mode code in any context where the occurrence of a FutureReservedWord would produce an error must also produce an equivalent error: implements let private public yield interface package protected static 7.7 Syntax Punctuator :: one of { } ( ) [ ] . ; , < > <= >= == != === !== + - * % ++ -- << >> >>> & | ^ ! ~ && || ? : = += -= *= %= <<= >>= >>>= &= |= ^= DivPunctuator :: one of / /= 7.8 Syntax Literal :: NullLiteral BooleanLiteral NumericLiteral StringLiteral RegularExpressionLiteral 7.8.1 Syntax NullLiteral :: null Semantics The value of the null literal null is the sole value of the Null type, namely null. 7.8.2 Syntax BooleanLiteral :: true false Semantics The value of the Boolean literal true is a value of the Boolean type, namely true. The value of the Boolean literal false is a value of the Boolean type, namely false. 7.8.3 Syntax NumericLiteral :: DecimalLiteral HexIntegerLiteral DecimalLiteral :: DecimalIntegerLiteral . DecimalDigits opt ExponentPart opt . DecimalDigits ExponentPart opt DecimalIntegerLiteral ExponentPart opt DecimalIntegerLiteral :: 0 NonZeroDigit DecimalDigits opt DecimalDigits :: DecimalDigit DecimalDigits DecimalDigit DecimalDigit :: one of 0 1 2 3 4 5 6 7 8 9 NonZeroDigit :: one of 1 2 3 4 5 6 7 8 9 ExponentPart :: ExponentIndicator SignedInteger ExponentIndicator :: one of e E SignedInteger :: DecimalDigits + DecimalDigits - DecimalDigits HexIntegerLiteral :: 0x HexDigit 0X HexDigit HexIntegerLiteral HexDigit HexDigit :: one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F The source character immediately following a NumericLiteral must not be an IdentifierStart or DecimalDigit. NOTE For example: 3in is an error and not the two input elements 3 and in . Semantics A numeric literal stands for a value of the Number type. This value is determined in two steps: first, a mathematical value (MV) is derived from the literal; second, this mathematical value is rounded as described below. The MV of NumericLiteral :: DecimalLiteral is the MV of DecimalLiteral .

The MV of NumericLiteral :: HexIntegerLiteral is the MV of HexIntegerLiteral .

The MV of DecimalLiteral :: DecimalIntegerLiteral . is the MV of DecimalIntegerLiteral .

The MV of DecimalLiteral :: DecimalIntegerLiteral . DecimalDigits is the MV of DecimalIntegerLiteral plus (the MV of DecimalDigits times 10 – n ), where n is the number of characters in DecimalDigit s.

The MV of DecimalLiteral :: DecimalIntegerLiteral . ExponentPart is the MV of DecimalIntegerLiteral times 10 e , where e is the MV of ExponentPart .

The MV of DecimalLiteral :: DecimalIntegerLiteral . DecimalDigits ExponentPart is (the MV of DecimalIntegerLiteral plus (the MV of DecimalDigits times 10 – n )) times 10 e , where n is the number of characters in DecimalDigit s and e is the MV of ExponentPart .

The MV of DecimalLiteral :: . DecimalDigits is the MV of DecimalDigits times 10 – n , where n is the number of characters in DecimalDigit s.

The MV of DecimalLiteral :: . DecimalDigits ExponentPart is the MV of DecimalDigits times 10 e – n , where n is the number of characters in DecimalDigit s and e is the MV of ExponentPart .

The MV of DecimalLiteral :: DecimalIntegerLiteral is the MV of DecimalIntegerLiteral .

The MV of DecimalLiteral :: DecimalIntegerLiteral ExponentPart is the MV of DecimalIntegerLiteral times 10 e , where e is the MV of ExponentPart .

The MV of DecimalIntegerLiteral :: 0 is 0.

The MV of DecimalIntegerLiteral :: NonZeroDigit is the MV of NonZeroDigit.

The MV of DecimalIntegerLiteral :: NonZeroDigit DecimalDigits is (the MV of NonZeroDigit times 10 n ) plus the MV of DecimalDigits , where n is the number of characters in DecimalDigits .

The MV of DecimalDigits :: DecimalDigit is the MV of DecimalDigit .

The MV of DecimalDigits :: DecimalDigits DecimalDigit is (the MV of DecimalDigits times 10) plus the MV of DecimalDigit .

The MV of ExponentPart :: ExponentIndicator SignedInteger is the MV of SignedInteger .

The MV of SignedInteger :: DecimalDigits is the MV of DecimalDigits .

The MV of SignedInteger :: + DecimalDigits is the MV of DecimalDigits .

The MV of SignedInteger :: - DecimalDigits is the negative of the MV of DecimalDigits .

The MV of DecimalDigit :: 0 or of HexDigit :: 0 is 0.

The MV of DecimalDigit :: 1 or of NonZeroDigit :: 1 or of HexDigit :: 1 is 1.

The MV of DecimalDigit :: 2 or of NonZeroDigit :: 2 or of HexDigit :: 2 is 2.

The MV of DecimalDigit :: 3 or of NonZeroDigit :: 3 or of HexDigit :: 3 is 3.

The MV of DecimalDigit :: 4 or of NonZeroDigit :: 4 or of HexDigit :: 4 is 4.

The MV of DecimalDigit :: 5 or of NonZeroDigit :: 5 or of HexDigit :: 5 is 5.

The MV of DecimalDigit :: 6 or of NonZeroDigit :: 6 or of HexDigit :: 6 is 6.

The MV of DecimalDigit :: 7 or of NonZeroDigit :: 7 or of HexDigit :: 7 is 7.

The MV of DecimalDigit :: 8 or of NonZeroDigit :: 8 or of HexDigit :: 8 is 8.

The MV of DecimalDigit :: 9 or of NonZeroDigit :: 9 or of HexDigit :: 9 is 9.

The MV of HexDigit :: a or of HexDigit :: A is 10.

The MV of HexDigit :: b or of HexDigit :: B is 11.

The MV of HexDigit :: c or of HexDigit :: C is 12.

The MV of HexDigit :: d or of HexDigit :: D is 13.

The MV of HexDigit :: e or of HexDigit :: E is 14.

The MV of HexDigit :: f or of HexDigit :: F is 15.

The MV of HexIntegerLiteral :: 0x HexDigit is the MV of HexDigit .

The MV of HexIntegerLiteral :: 0X HexDigit is the MV of HexDigit .

The MV of HexIntegerLiteral :: HexIntegerLiteral HexDigit is (the MV of HexIntegerLiteral times 16) plus the MV of HexDigit. Once the exact MV for a numeric literal has been determined, it is then rounded to a value of the Number type. If the MV is 0, then the rounded value is +0; otherwise, the rounded value must be the Number value for the MV (as specified in 8.5), unless the literal is a DecimalLiteral and the literal has more than 20 significant digits, in which case the Number value may be either the Number value for the MV of a literal produced by replacing each significant digit after the 20th with a 0 digit or the Number value for the MV of a literal produced by replacing each significant digit after the 20th with a 0 digit and then incrementing the literal at the 20th significant digit position. A digit is significant if it is not part of an ExponentPart and it is not 0 ; or

; or there is a nonzero digit to its left and there is a nonzero digit, not in the ExponentPart, to its right. A conforming implementation, when processing strict mode code (see 10.1.1), must not extend the syntax of NumericLiteral to include OctalIntegerLiteral as described in B.1.1. 7.8.4 A string literal is zero or more characters enclosed in single or double quotes. Each character may be represented by an escape sequence. All characters may appear literally in a string literal except for the closing quote character, backslash, carriage return, line separator, paragraph separator, and line feed. Any character may appear in the form of an escape sequence. Syntax StringLiteral :: " DoubleStringCharacters opt " ' SingleStringCharacters opt ' DoubleStringCharacters :: DoubleStringCharacter DoubleStringCharacters opt SingleStringCharacters :: SingleStringCharacter SingleStringCharacters opt DoubleStringCharacter :: SourceCharacter but not one of " or \ or LineTerminator \ EscapeSequence LineContinuation SingleStringCharacter :: SourceCharacter but not one of ' or \ or LineTerminator \ EscapeSequence LineContinuation LineContinuation :: \ LineTerminatorSequence EscapeSequence :: CharacterEscapeSequence 0 [lookahead ∉ DecimalDigit ] HexEscapeSequence UnicodeEscapeSequence CharacterEscapeSequence :: SingleEscapeCharacter NonEscapeCharacter SingleEscapeCharacter :: one of ' " \ b f n r t v NonEscapeCharacter :: SourceCharacter but not one of EscapeCharacter or LineTerminator EscapeCharacter :: SingleEscapeCharacter DecimalDigit x u HexEscapeSequence :: x HexDigit HexDigit UnicodeEscapeSequence :: u HexDigit HexDigit HexDigit HexDigit The definition of the nonterminal HexDigit is given in 7.8.3. SourceCharacter is defined in clause 6. Semantics A string literal stands for a value of the String type. The String value (SV) of the literal is described in terms of character values (CV) contributed by the various parts of the string literal. As part of this process, some characters within the string literal are interpreted as having a mathematical value (MV), as described below or in 7.8.3. The SV of StringLiteral :: "" is the empty character sequence.

The SV of StringLiteral :: '' is the empty character sequence.

The SV of StringLiteral :: " DoubleStringCharacters " is the SV of DoubleStringCharacters .

The SV of StringLiteral :: ' SingleStringCharacters ' is the SV of SingleStringCharacters .

The SV of DoubleStringCharacters :: DoubleStringCharacter is a sequence of one character, the CV of DoubleStringCharacter .

The SV of DoubleStringCharacters :: DoubleStringCharacter DoubleStringCharacters is a sequence of the CV of DoubleStringCharacter followed by all the characters in the SV of DoubleStringCharacters in order.

The SV of SingleStringCharacters :: SingleStringCharacter is a sequence of one character, the CV of SingleStringCharacter .

The SV of SingleStringCharacters :: SingleStringCharacter SingleStringCharacters is a sequence of the CV of SingleStringCharacter followed by all the characters in the SV of SingleStringCharacters in order.

The SV of LineContinuation :: \ LineTerminatorSequence is the empty character sequence.

The CV of DoubleStringCharacter :: SourceCharacter but not one of " or \ or LineTerminator is the SourceCharacter character itself.

The CV of DoubleStringCharacter :: \ EscapeSequence is the CV of the EscapeSequence .

The CV of DoubleStringCharacter :: LineContinuation is the empty character sequence.

The CV of SingleStringCharacter :: SourceCharacter but not one of ' or \ or LineTerminator is the SourceCharacter character itself.

The CV of SingleStringCharacter :: \ EscapeSequence is the CV of the EscapeSequence .

The CV of SingleStringCharacter :: LineContinuation is the empty character sequence.

The CV of EscapeSequence :: CharacterEscapeSequence is the CV of the CharacterEscapeSequence .

The CV of EscapeSequence :: 0 [lookahead ∉ DecimalDigit] is a <NUL> character (Unicode value 0000).

The CV of EscapeSequence :: HexEscapeSequence is the CV of the HexEscapeSequence .

The CV of EscapeSequence :: UnicodeEscapeSequence is the CV of the UnicodeEscapeSequence .

The CV of CharacterEscapeSequence :: SingleEscapeCharacter is the character whose code unit value is determined by the SingleEscapeCharacter according to Table 4: Table 4 — String Single Character Escape Sequences Escape Sequence Code Unit Value Name Symbol \b \u0008 backspace <BS> \t \u0009 horizontal tab <HT>

\u000A line feed (new line) <LF> \v \u000B vertical tab <VT> \f \u000C form feed <FF> \r \u000D carriage return <CR> \" \u0022 double quote " \' \u0027 single quote ' \\ \u005C backslash \ The CV of CharacterEscapeSequence :: NonEscapeCharacter is the CV of the NonEscapeCharacter .

The CV of NonEscapeCharacter :: SourceCharacter but not one of EscapeCharacter or LineTerminator is the SourceCharacter character itself.

The CV of HexEscapeSequence :: x HexDigit HexDigit is the character whose code unit value is (16 times the MV of the first HexDigit ) plus the MV of the second HexDigit .

The CV of UnicodeEscapeSequence :: u HexDigit HexDigit HexDigit HexDigit is the character whose code unit value is (4096 times the MV of the first HexDigit) plus (256 times the MV of the second HexDigit) plus (16 times the MV of the third HexDigit) plus the MV of the fourth HexDigit. A conforming implementation, when processing strict mode code (see 10.1.1), may not extend the syntax of EscapeSequence to include OctalEscapeSequence as described in B.1.2. NOTE A line terminator character cannot appear in a string literal, except as part of a LineContinuation to produce the empty character sequence. The correct way to cause a line terminator character to be part of the String value of a string literal is to use an escape sequence such as

or \u000A . 7.8.5 A regular expression literal is an input element that is converted to a RegExp object (see 15.10) each time the literal is evaluated. Two regular expression literals in a program evaluate to regular expression objects that never compare as === to each other even if the two literals' contents are identical. A RegExp object may also be created at runtime by new RegExp (see 15.10.4) or calling the RegExp constructor as a function (15.10.3). The productions below describe the syntax for a regular expression literal and are used by the input element scanner to find the end of the regular expression literal. The Strings of characters comprising the RegularExpressionBody and the RegularExpressionFlags are passed uninterpreted to the regular expression constructor, which interprets them according to its own, more stringent grammar. An implementation may extend the regular expression constructor's grammar, but it must not extend the RegularExpressionBody and RegularExpressionFlags productions or the productions used by these productions. Syntax RegularExpressionLiteral :: / RegularExpressionBody / RegularExpressionFlags RegularExpressionBody :: RegularExpressionFirstChar RegularExpressionChars RegularExpressionChars :: [empty] RegularExpressionChars RegularExpressionChar RegularExpressionFirstChar :: RegularExpressionNonTerminator but not one of * or \ or / or [ RegularExpressionBackslashSequence RegularExpressionClass RegularExpressionChar :: RegularExpressionNonTerminator but not one of \ or / or [ RegularExpressionBackslashSequence RegularExpressionClass RegularExpressionBackslashSequence :: \ RegularExpressionNonTerminator RegularExpressionNonTerminator :: SourceCharacter but not LineTerminator RegularExpressionClass :: [ RegularExpressionClassChars ] RegularExpressionClassChars :: [empty] RegularExpressionClassChars RegularExpressionClassChar RegularExpressionClassChar :: RegularExpressionNonTerminator but not one of ] or \ RegularExpressionBackslashSequence RegularExpressionFlags :: [empty] RegularExpressionFlags IdentifierPart NOTE Regular expression literals may not be empty; instead of representing an empty regular expression literal, the characters // start a single-line comment. To specify an empty regular expression, use: /(?:)/ . Semantics A regular expression literal evaluates to a value of the Object type that is an instance of the standard built-in constructor RegExp. This value is determined in two steps: first, the characters comprising the regular expression's RegularExpressionBody and RegularExpressionFlags production expansions are collected uninterpreted into two Strings Pattern and Flags, respectively. Then each time the literal is evaluated, a new object is created as if by the expression new RegExp(Pattern, Flags) where RegExp is the standard built-in constructor with that name. The newly constructed object becomes the value of the RegularExpressionLiteral. If the call to new RegExp would generate an error as specified in 15.10.4.1, the error must be treated as an early error (Clause 16). 7.9 Certain ECMAScript statements (empty statement, variable statement, expression statement, do - while statement, continue statement, break statement, return statement, and throw statement) must be terminated with semicolons. Such semicolons may always appear explicitly in the source text. For convenience, however, such semicolons may be omitted from the source text in certain situations. These situations are described by saying that semicolons are automatically inserted into the source code token stream in those situations. 7.9.1 There are three basic rules of semicolon insertion: When, as the program is parsed from left to right, a token (called the offending token) is encountered that is not allowed by any production of the grammar, then a semicolon is automatically inserted before the offending token if one or more of the following conditions is true: The offending token is separated from the previous token by at least one LineTerminator .

. The offending token is } . When, as the program is parsed from left to right, the end of the input stream of tokens is encountered and the parser is unable to parse the input token stream as a single complete ECMAScript Program , then a semicolon is automatically inserted at the end of the input stream. When, as the program is parsed from left to right, a token is encountered that is allowed by some production of the grammar, but the production is a restricted production and the token would be the first token for a terminal or nonterminal immediately following the annotation “ [no LineTerminator here] ” within the restricted production (and therefore such a token is called a restricted token), and the restricted token is separated from the previous token by at least one LineTerminator , then a semicolon is automatically inserted before the restricted token. However, there is an additional overriding condition on the preceding rules: a semicolon is never inserted automatically if the semicolon would then be parsed as an empty statement or if that semicolon would become one of the two semicolons in the header of a for statement (see 12.6.3). NOTE The following are the only restricted productions in the grammar: PostfixExpression : LeftHandSideExpression [no LineTerminator here] ++ LeftHandSideExpression [no LineTerminator here] -- ContinueStatement : continue [no LineTerminator here] Identifier ; BreakStatement : break [no LineTerminator here] Identifier ; ReturnStatement : return [no LineTerminator here] Expression ; ThrowStatement : throw [no LineTerminator here] Expression ; The practical effect of these restricted productions is as follows: When a ++ or -- token is encountered where the parser would treat it as a postfix operator, and at least one LineTerminator occurred between the preceding token and the ++ or -- token, then a semicolon is automatically inserted before the ++ or -- token. When a continue , break , return , or throw token is encountered and a LineTerminator is encountered before the next token, a semicolon is automatically inserted after the continue , break , return , or throw token. The resulting practical advice to ECMAScript programmers is: A postfix ++ or -- operator should appear on the same line as its operand. An Expression in a return or throw statement should start on the same line as the return or throw token. An Identifier in a break or continue statement should be on the same line as the break or continue token. 7.9.2 The source { 1 2 } 3 is not a valid sentence in the ECMAScript grammar, even with the automatic semicolon insertion rules. In contrast, the source { 1

2 } 3 is also not a valid ECMAScript sentence, but is transformed by automatic semicolon insertion into the following: { 1

;2 ;} 3; which is a valid ECMAScript sentence. The source for (a; b

) is not a valid ECMAScript sentence and is not altered by automatic semicolon insertion because the semicolon is needed for the header of a for statement. Automatic semicolon insertion never inserts one of the two semicolons in the header of a for statement. The source return

a + b is transformed by automatic semicolon insertion into the following: return;

a + b; NOTE The expression a + b is not treated as a value to be returned by the return statement, because a LineTerminator separates it from the token return . The source a = b

++c is transformed by automatic semicolon insertion into the following: a = b;

++c; NOTE The token ++ is not treated as a postfix operator applying to the variable b , because a LineTerminator occurs between b and ++ . The source if (a > b)

else c = d is not a valid ECMAScript sentence and is not altered by automatic semicolon insertion before the else token, even though no production of the grammar applies at that point, because an automatically inserted semicolon would then be parsed as an empty statement. The source a = b + c

(d + e).print() is not transformed by automatic semicolon insertion, because the parenthesised expression that begins the second line can be interpreted as an argument list for a function call: a = b + c(d + e).print() In the circumstance that an assignment statement must begin with a left parenthesis, it is a good idea for the programmer to provide an explicit semicolon at the end of the preceding statement rather than to rely on automatic semicolon insertion.

9 The ECMAScript runtime system performs automatic type conversion as needed. To clarify the semantics of certain constructs it is useful to define a set of conversion abstract operations. These abstract operations are not a part of the language; they are defined here to aid the specification of the semantics of the language. The conversion abstract operations are polymorphic; that is, they can accept a value of any ECMAScript language type, but not of specification types. 9.1 The abstract operation ToPrimitive takes an input argument and an optional argument PreferredType. The abstract operation ToPrimitive converts its input argument to a non-Object type. If an object is capable of converting to more than one primitive type, it may use the optional hint PreferredType to favour that type. Conversion occurs according to Table 10: Table 10 — ToPrimitive Conversions Input Type Result Undefined The result equals the input argument (no conversion). Null The result equals the input argument (no conversion). Boolean The result equals the input argument (no conversion). Number The result equals the input argument (no conversion). String The result equals the input argument (no conversion). Object Return a default value for the Object. The default value of an object is retrieved by calling the [[DefaultValue]] internal method of the object, passing the optional hint PreferredType . The behaviour of the [[DefaultValue]] internal method is defined by this specification for all native ECMAScript objects in 8.12.8. 9.2 The abstract operation ToBoolean converts its argument to a value of type Boolean according to Table 11: Table 11 — ToBoolean Conversions Argument Type Result Undefined false Null false Boolean The result equals the input argument (no conversion). Number The result is false if the argument is +0, −0, or NaN; otherwise the result is true. String The result is false if the argument is the empty String (its length is zero); otherwise the result is true. Object true 9.3 The abstract operation ToNumber converts its argument to a value of type Number according to Table 12: Table 12 — To Number Conversions Argument Type Result Undefined NaN Null +0 Boolean The result is 1 if the argument is true. The result is +0 if the argument is false. Number The result equals the input argument (no conversion). String See grammar and note below. Object Apply the following steps: Let primValue be ToPrimitive(input argument, hint Number). Return ToNumber(primValue). 9.3.1 ToNumber applied to Strings applies the following grammar to the input String. If the grammar cannot interpret the String as an expansion of StringNumericLiteral, then the result of ToNumber is NaN. Syntax StringNumericLiteral ::: StrWhiteSpace opt StrWhiteSpace opt StrNumericLiteral StrWhiteSpace opt StrWhiteSpace ::: StrWhiteSpaceChar StrWhiteSpace opt StrWhiteSpaceChar ::: WhiteSpace LineTerminator StrNumericLiteral ::: StrDecimalLiteral HexIntegerLiteral StrDecimalLiteral ::: StrUnsignedDecimalLiteral + StrUnsignedDecimalLiteral - StrUnsignedDecimalLiteral StrUnsignedDecimalLiteral ::: Infinity DecimalDigits . DecimalDigits opt ExponentPart opt . DecimalDigits ExponentPart opt DecimalDigits ExponentPart opt DecimalDigits ::: DecimalDigit DecimalDigits DecimalDigit DecimalDigit ::: one of 0 1 2 3 4 5 6 7 8 9 ExponentPart ::: ExponentIndicator SignedInteger ExponentIndicator ::: one of e E SignedInteger ::: DecimalDigits + DecimalDigits - DecimalDigits HexIntegerLiteral ::: 0x HexDigit 0X HexDigit HexIntegerLiteral HexDigit HexDigit ::: one of 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F Some differences should be noted between the syntax of a StringNumericLiteral and a NumericLiteral (see 7.8.3): A StringNumericLiteral may be preceded and/or followed by white space and/or line terminators.

A StringNumericLiteral that is decimal may have any number of leading 0 digits.

A StringNumericLiteral that is decimal may be preceded by + or - to indicate its sign.

A StringNumericLiteral that is empty or contains only white space is converted to +0. The conversion of a String to a Number value is similar overall to the determination of the Number value for a numeric literal (see 7.8.3), but some of the details are different, so the process for converting a String numeric literal to a value of Number type is given here in full. This value is determined in two steps: first, a mathematical value (MV) is derived from the String numeric literal; second, this mathematical value is rounded as described below. The MV of StringNumericLiteral ::: [empty] is 0.

The MV of StringNumericLiteral ::: StrWhiteSpace is 0.

The MV of StringNumericLiteral ::: StrWhiteSpace opt StrNumericLiteral StrWhiteSpace opt is the MV of StrNumericLiteral, no matter whether white space is present or not.

The MV of StrNumericLiteral ::: StrDecimalLiteral is the MV of StrDecimalLiteral.

The MV of StrNumericLiteral ::: HexIntegerLiteral is the MV of HexIntegerLiteral.

The MV of StrDecimalLiteral ::: StrUnsignedDecimalLiteral is the MV of StrUnsignedDecimalLiteral.

The MV of StrDecimalLiteral ::: + StrUnsignedDecimalLiteral is the MV of StrUnsignedDecimalLiteral.

The MV of StrDecimalLiteral ::: - StrUnsignedDecimalLiteral is the negative of the MV of StrUnsignedDecimalLiteral. (Note that if the MV of StrUnsignedDecimalLiteral is 0, the negative of this MV is also 0. The rounding rule described below handles the conversion of this signless mathematical zero to a floating-point +0 or −0 as appropriate.)

The MV of StrUnsignedDecimalLiteral ::: Infinity is 10 10000 (a value so large that it will round to +∞ ).

The MV of StrUnsignedDecimalLiteral ::: DecimalDigits . is the MV of DecimalDigits.

The MV of StrUnsignedDecimalLiteral ::: DecimalDigits . DecimalDigits is the MV of the first DecimalDigits plus (the MV of the second DecimalDigits times 10 − n ), where n is the number of characters in the second DecimalDigits.

The MV of StrUnsignedDecimalLiteral ::: DecimalDigits . ExponentPart is the MV of DecimalDigits times 10 e , where e is the MV of ExponentPart .

The MV of StrUnsignedDecimalLiteral ::: DecimalDigits . DecimalDigits ExponentPart is (the MV of the first DecimalDigits plus (the MV of the second DecimalDigits times 10 − n )) times 10 e , where n is the number of characters in the second DecimalDigit s and e is the MV of ExponentPart .

The MV of StrUnsignedDecimalLiteral ::: . DecimalDigits is the MV of DecimalDigits times 10 − n , where n is the number of characters in DecimalDigit s.

The MV of StrUnsignedDecimalLiteral ::: . DecimalDigits ExponentPart is the MV of DecimalDigits times 10 e − n , where n is the number of characters in DecimalDigit s and e is the MV of ExponentPart .

The MV of StrUnsignedDecimalLiteral ::: DecimalDigits is the MV of DecimalDigits .

The MV of StrUnsignedDecimalLiteral ::: DecimalDigits ExponentPart is the MV of DecimalDigits times 10 e , where e is the MV of ExponentPart .

The MV of DecimalDigits ::: DecimalDigit is the MV of DecimalDigit .

The MV of DecimalDigits ::: DecimalDigits DecimalDigit is (the MV of DecimalDigits times 10) plus the MV of DecimalDigit .

The MV of ExponentPart ::: ExponentIndicator SignedInteger is the MV of SignedInteger .

The MV of SignedInteger ::: DecimalDigits is the MV of DecimalDigits .

The MV of SignedInteger ::: + DecimalDigits is the MV of DecimalDigits .

The MV of SignedInteger ::: - DecimalDigits is the negative of the MV of DecimalDigits .

The MV of DecimalDigit ::: 0 or of HexDigit ::: 0 is 0.

The MV of DecimalDigit ::: 1 or of HexDigit ::: 1 is 1.

The MV of DecimalDigit ::: 2 or of HexDigit ::: 2 is 2.

The MV of DecimalDigit ::: 3 or of HexDigit ::: 3 is 3.

The MV of DecimalDigit ::: 4 or of HexDigit ::: 4 is 4.

The MV of DecimalDigit ::: 5 or of HexDigit ::: 5 is 5.

The MV of DecimalDigit ::: 6 or of HexDigit ::: 6 is 6.

The MV of DecimalDigit ::: 7 or of HexDigit ::: 7 is 7.

The MV of DecimalDigit ::: 8 or of HexDigit ::: 8 is 8.

The MV of DecimalDigit ::: 9 or of HexDigit ::: 9 is 9.

The MV of HexDigit ::: a or of HexDigit ::: A is 10.

The MV of HexDigit ::: b or of HexDigit ::: B is 11.

The MV of HexDigit ::: c or of HexDigit ::: C is 12.

The MV of HexDigit ::: d or of HexDigit ::: D is 13.

The MV of HexDigit ::: e or of HexDigit ::: E is 14.

The MV of HexDigit ::: f or of HexDigit ::: F is 15.

The MV of HexIntegerLiteral ::: 0x HexDigit is the MV of HexDigit .

The MV of HexIntegerLiteral ::: 0X HexDigit is the MV of HexDigit .

The MV of HexIntegerLiteral ::: HexIntegerLiteral HexDigit is (the MV of HexIntegerLiteral times 16) plus the MV of HexDigit. Once the exact MV for a String numeric literal has been determined, it is then rounded to a value of the Number type. If the MV is 0, then the rounded value is +0 unless the first non white space character in the String numeric literal is ‘ - ’, in which case the rounded value is −0. Otherwise, the rounded value must be the Number value for the MV (in the sense defined in 8.5), unless the literal includes a StrUnsignedDecimalLiteral and the literal has more than 20 significant digits, in which case the Number value may be either the Number value for the MV of a literal produced by replacing each significant digit after the 20th with a 0 digit or the Number value for the MV of a literal produced by replacing each significant digit after the 20th with a 0 digit and then incrementing the literal at the 20th digit position. A digit is significant if it is not part of an ExponentPart and it is not 0 ; or

; or there is a nonzero digit to its left and there is a nonzero digit, not in the ExponentPart , to its right. 9.4 The abstract operation ToInteger converts its argument to an integral numeric value. This abstract operation functions as follows: Let number be the result of calling ToNumber on the input argument. If number is NaN, return +0. If number is +0, −0, +∞, or −∞, return number. Return the result of computing sign(number) × floor(abs(number)). 9.5 The abstract operation ToInt32 converts its argument to one of 232 integer values in the range −231 through 231−1, inclusive. This abstract operation functions as follows: Let number be the result of calling ToNumber on the input argument. If number is NaN, +0, −0, +∞, or −∞, return +0. Let posInt be sign(number) * floor(abs(number)). Let int32bit be posInt modulo 232; that is, a finite integer value k of Number type with positive sign and less than 232 in magnitude such that the mathematical difference of posInt and k is mathematically an integer multiple of 232. If int32bit is greater than or equal to 231, return int32bit − 232, otherwise return int32bit. NOTE Given the above definition of ToInt32: The ToInt32 abstract operation is idempotent: if applied to a result that it produced, the second application leaves that value unchanged.

ToInt32(ToUint32(x)) is equal to ToInt32( x ) for all values of x . (It is to preserve this latter property that + ∞ and − ∞ are mapped to +0 .)

ToInt32 maps −0 to +0. 9.6 The abstract operation ToUint32 converts its argument to one of 232 integer values in the range 0 through 232−1, inclusive. This abstraction operation functions as follows: Let number be the result of calling ToNumber on the input argument. If number is NaN, +0, −0, +∞, or −∞, return +0. Let posInt be sign(number) × floor(abs(number)). Let int32bit be posInt modulo 232; that is, a finite integer value k of Number type with positive sign and less than 232 in magnitude such that the mathematical difference of posInt and k is mathematically an integer multiple of 232. Return int32bit. NOTE Given the above definition of ToUInt32: Step 5 is the only difference between ToUint32 and ToInt32.

The ToUint32 abstract operation is idempotent: if applied to a result that it produced, the second application leaves that value unchanged.

ToUint32(ToInt32( x )) is equal to ToUint32( x ) for all values of x . (It is to preserve this latter property that +∞ and −∞ are mapped to +0 .)

ToUint32 maps −0 to +0. 9.7 The abstract operation ToUint16 converts its argument to one of 216 integer values in the range 0 through 216−1, inclusive. This abstract operation functions as follows: Let number be the result of calling ToNumber on the input argument. If number is NaN, +0, −0, +∞, or −∞, return +0. Let posInt be sign(number) × floor(abs(number)). Let int16bit be posInt modulo 216; that is, a finite integer value k of Number type with positive sign and less than 216 in magnitude such that the mathematical difference of posInt and k is mathematically an integer multiple of 216. Return int16bit. NOTE Given the above definition of ToUint16: The substitution of 2 16 for 2 32 in step 4 is the only difference between ToUint32 and ToUint16.

for in step 4 is the only difference between ToUint32 and ToUint16. ToUint16 maps −0 to +0. 9.8 The abstract operation ToString converts its argument to a value of type String according to Table 13: Table 13 — ToString Conversions Argument Type Result Undefined "undefined" Null "null" Boolean If the argument is true, then the result is "true" . If the argument is false, then the result is "false". Number See 9.8.1. String Return the input argument (no conversion) Object Apply the following steps: 1. Let primValue be ToPrimitive(input argument, hint String). 2. Return ToString(primValue). 9.8.1 The abstract operation ToString converts a Number m to String format as follows: If m is NaN, return the String "NaN" . If m is +0 or −0, return the String "0" . If m is less than zero, return the String concatenation of the String "-" and ToString(−m). If m is infinity, return the String "Infinity" . Otherwise, let n, k, and s be integers such that k ≥ 1, 10k−1 ≤ s < 10k, the Number value for s × 10n−k is m, and k is as small as possible. Note that k is the number of digits in the decimal representation of s, that s is not divisible by 10, and that the least significant digit of s is not necessarily uniquely determined by these criteria. If k ≤ n ≤ 21, return the String consisting of the k digits of the decimal representation of s (in order, with no leading zeroes), followed by n−k occurrences of the character ‘ 0 ’. If 0 < n ≤ 21, return the String consisting of the most significant n digits of the decimal representation of s, followed by a decimal point ‘ . ’, followed by the remaining k−n digits of the decimal representation of s. If −6 < n ≤ 0, return the String consisting of the character ‘ 0 ’, followed by a decimal point ‘ . ’, followed by −n occurrences of the character ‘ 0 ’, followed by the k digits of the decimal representation of s. Otherwise, if k = 1, return the String consisting of the single digit of s, followed by lowercase character ‘ e ’, followed by a plus sign ‘ + ’ or minus sign ‘ − ’ according to whether n−1 is positive or negative, followed by the decimal representation of the integer abs(n−1) (with no leading zeroes). Return the String consisting of the most significant digit of the decimal representation of s, followed by a decimal point ‘.’, followed by the remaining k−1 digits of the decimal representation of s, followed by the lowercase character ‘ e ’, followed by a plus sign ‘ + ’ or minus sign ‘ − ’ according to whether n−1 is positive or negative, followed by the decimal representation of the integer abs(n−1) (with no leading zeroes). NOTE 1 The following observations may be useful as guidelines for implementations, but are not part of the normative requirements of this Standard: If x is any Number value other than −0 , then ToNumber(ToString(x)) is exactly the same Number value as x.

The least significant digit of s is not always uniquely determined by the requirements listed in step 5. NOTE 2 For implementations that provide more accurate conversions than required by the rules above, it is recommended that the following alternative version of step 5 be used as a guideline: Otherwise, let n, k, and s be integers such that k ≥ 1, 10k−1 ≤ s < 10k, the Number value for s × 10n−k is m, and k is as small as possible. If there are multiple possibilities for s, choose the value of s for which s × 10n−k is closest in value to m. If there are two such possible values of s, choose the one that is even. Note that k is the number of digits in the decimal representation of s and that s is not divisible by 10. NOTE 3 Implementers of ECMAScript may find useful the paper and code written by David M. Gay for binary-to-decimal conversion of floating-point numbers: Gay, David M. Correctly Rounded Binary-Decimal and Decimal-Binary Conversions. Numerical Analysis, Manuscript 90-10. AT&T Bell Laboratories (Murray Hill, New Jersey). November 30, 1990. Available as

http://cm.bell-labs.com/cm/cs/doc/90/4-10.ps.gz. Associated code available as

http://cm.bell-labs.com/netlib/fp/dtoa.c.gz and as

http://cm.bell-labs.com/netlib/fp/g_fmt.c.gz and may also be found at the various netlib mirror sites. 9.9 The abstract operation ToObject converts its argument to a value of type Object according to Table 14: Table 14 — ToObject Argument Type Result Undefined Throw a TypeError exception. Null Throw a TypeError exception. Boolean Create a new Boolean object whose [[PrimitiveValue]] internal property is set to the value of the argument. See 15.6 for a description of Boolean objects. Number Create a new Number object whose [[PrimitiveValue]] internal property is set to the value of the argument. See 15.7 for a description of Number objects. String Create a new String object whose [[PrimitiveValue]] internal property is set to the value of the argument. See 15.5 for a description of String objects. Object The result is the input argument (no conversion). 9.10 The abstract operation CheckObjectCoercible throws an error if its argument is a value that cannot be converted to an Object using ToObject. It is defined by Table 15: Table 15 — CheckObjectCoercible Results Argument Type Result Undefined Throw a TypeError exception. Null Throw a TypeError exception. Boolean Return Number Return String Return Object Return 9.11 The abstract operation IsCallable determines if its argument, which must be an ECMAScript language value, is a callable function Object according to Table 16: Table 16 — IsCallable Results Argument Type Result Undefined Return false. Null Return false. Boolean Return false. Number Return false. String Return false. Object If the argument object has a [[Call]] internal method, then return true, otherwise return false. 9.12 The internal comparison abstract operation SameValue( x , y ), where x and y are ECMAScript language values, produces true or false. Such a comparison is performed as follows: If Type(x) is different from Type(y), return false. If Type(x) is Undefined, return true. If Type(x) is Null, return true. If Type(x) is Number, then. If x is NaN and y is NaN, return true. If x is +0 and y is -0, return false. If x is -0 and y is +0, return false. If x is the same Number value as y, return true. Return false. If Type(x) is String, then return true if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions); otherwise, return false. If Type(x) is Boolean, return true if x and y are both true or both false; otherwise, return false. Return true if x and y refer to the same object. Otherwise, return false.

12 Syntax Statement : Block VariableStatement EmptyStatement ExpressionStatement IfStatement IterationStatement ContinueStatement BreakStatement ReturnStatement WithStatement LabelledStatement SwitchStatement ThrowStatement TryStatement DebuggerStatement Semantics A Statement can be part of a LabelledStatement, which itself can be part of a LabelledStatement, and so on. The labels introduced this way are collectively referred to as the “current label set” when describing the semantics of individual statements. A LabelledStatement has no semantic meaning other than the introduction of a label to a label set. The label set of an IterationStatement or a SwitchStatement initially contains the single element empty. The label set of any other statement is initially empty. The result of evaluating a Statement is always a Completion value. NOTE Several widely used implementations of ECMAScript are known to support the use of FunctionDeclaration as a Statement. However there are significant and irreconcilable variations among the implementations in the semantics applied to such FunctionDeclarations. Because of these irreconcilable differences, the use of a FunctionDeclaration as a Statement results in code that is not reliably portable among implementations. It is recommended that ECMAScript implementations either disallow this usage of FunctionDeclaration or issue a warning when such a usage is encountered. Future editions of ECMAScript may define alternative portable means for declaring functions in a Statement context. 12.1 Syntax Block : { StatementList opt } StatementList : Statement StatementList Statement Semantics The production Block : { } is evaluated as follows: Return (normal, empty, empty). The production Block : { StatementList } is evaluated as follows: Return the result of evaluating StatementList. The production StatementList : Statement is evaluated as follows: Let s be the result of evaluating Statement. If an exception was thrown, return ( throw , V, empty ) where V is the exception. (Execution now proceeds as if no exception were thrown.) Return s. The production StatementList : StatementList Statement is evaluated as follows: Let sl be the result of evaluating StatementList. If sl is an abrupt completion, return sl. Let s be the result of evaluating Statement. If an exception was thrown, return ( throw , V, empty ) where V is the exception. (Execution now proceeds as if no exception were thrown.) If s.value is empty , let V = sl.value, otherwise let V = s.value. Return (s.type, V, s.target). NOTE Steps 5 and 6 of the above algoritm ensure that the value of a StatementList is the value of the last value producing Statement in the StatementList. For example, the following calls to the eval function all return the value 1: eval("1;;;;;") eval("1;{}") eval("1;var a;") 12.2 Syntax VariableStatement : var VariableDeclarationList ; VariableDeclarationList : VariableDeclaration VariableDeclarationList , VariableDeclaration VariableDeclarationListNoIn : VariableDeclarationNoIn VariableDeclarationListNoIn , VariableDeclarationNoIn VariableDeclaration : Identifier Initialiser opt VariableDeclarationNoIn : Identifier InitialiserNoIn opt Initialiser : = AssignmentExpression InitialiserNoIn : = AssignmentExpressionNoIn A variable statement declares variables that are created as defined in 10.5. Variables are initialised to undefined when created. A variable with an Initialiser is assigned the value of its AssignmentExpression when the VariableStatement is executed, not when the variable is created. Semantics The production VariableStatement : var VariableDeclarationList ; is evaluated as follows: Evaluate VariableDeclarationList. Return ( normal , empty , empty ). The production VariableDeclarationList :VariableDeclaration is evaluated as follows: Evaluate VariableDeclaration. The production VariableDeclarationList : VariableDeclarationList , VariableDeclaration is evaluated as follows: Evaluate VariableDeclarationList. Evaluate VariableDeclaration. The production VariableDeclaration : Identifier is evaluated as follows: Return a String value containing the same sequence of characters as in the Identifier. The production VariableDeclaration : Identifier Initialiser is evaluated as follows: Let lhs be the result of evaluating Identifier as described in 11.1.2. Let rhs be the result of evaluating Initialiser. L