☰

ECMA-262

7ᵗʰ Edition / June 2016

ECMAScript® 2016 Language Specification

Introduction # This Ecma Standard defines the ECMAScript 2016 Language. It is the seventh edition of the ECMAScript Language Specification. Since publication of the first edition in 1997, ECMAScript has grown to be one of the world's most widely used general purpose programming languages. It is best known as the language embedded in web browsers but has also been widely adopted for server and embedded applications. ECMAScript 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 the ECMAScript Language Specification 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 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. After publication of the third edition, ECMAScript 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. However, that work was not completed and not published as the fourth edition of ECMAScript but some of it was incorporated into the development of the sixth edition. The fifth edition of ECMAScript (published as ECMA-262 5th edition) codified de facto interpretations of the language specification that have become common among browser implementations and added support for new features that had 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. The Fifth Edition was adopted by the Ecma General Assembly of December 2009. The fifth Edition was submitted to ISO/IEC JTC 1 for adoption under the fast-track procedure, and approved as international standard ISO/IEC 16262:2011. Edition 5.1 of the ECMAScript Standard incorporated minor corrections and is the same text as ISO/IEC 16262:2011. The 5.1 Edition was adopted by the Ecma General Assembly of June 2011. Focused development of the sixth edition started in 2009, as the fifth edition was being prepared for publication. However, this was preceded by significant experimentation and language enhancement design efforts dating to the publication of the third edition in 1999. In a very real sense, the completion of the sixth edition is the culmination of a fifteen year effort. The goals for this addition included providing better support for large applications, library creation, and for use of ECMAScript as a compilation target for other languages. Some of its major enhancements included modules, class declarations, lexical block scoping, iterators and generators, promises for asynchronous programming, destructuring patterns, and proper tail calls. The ECMAScript library of built-ins was expanded to support additional data abstractions including maps, sets, and arrays of binary numeric values as well as additional support for Unicode supplemental characters in strings and regular expressions. The built-ins were also made extensible via subclassing. The sixth edition provides the foundation for regular, incremental language and library enhancements. The sixth edition was adopted by the General Assembly of June 2015. This ECMAScript specification is the first ECMAScript edition released under Ecma TC39's new yearly release cadence and open development process. A plain-text source document was built from the ECMAScript 2015 source document to serve as the base for further development entirely on GitHub. Over the year of this standard's development, hundreds of pull requests and issues were filed representing thousands of bug fixes, editorial fixes and other improvements. Additionally, numerous software tools were developed to aid in this effort including Ecmarkup, Ecmarkdown, and Grammarkdown. This specification also includes support for a new exponentiation operator and adds a new method to Array.prototype called includes . Dozens of individuals representing many organizations have made very significant contributions within Ecma TC39 to the development of this edition and to the prior editions. In addition, a vibrant community has emerged supporting TC39's ECMAScript efforts. This community has reviewed numerous drafts, filed thousands of bug reports, performed implementation experiments, contributed test suites, and educated the world-wide developer community about ECMAScript. Unfortunately, it is impossible to identify and acknowledge every person and organization who has contributed to this effort. Allen Wirfs-Brock

ECMA-262, 6th Edition Project Editor Brian Terlson

ECMA-262, 7th Edition Project Editor

1 Scope # This Standard defines the ECMAScript 2016 general purpose programming language.

2 Conformance # 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 ECMAScript must interpret source text input in conformance with the Unicode Standard, Version 8.0.0 or later and ISO/IEC 10646. A conforming implementation of ECMAScript that provides an application programming interface that supports programs that need to adapt to the linguistic and cultural conventions used by different human languages and countries must implement the interface defined by the most recent edition of ECMA-402 that is compatible with this specification. A conforming implementation of ECMAScript may provide additional types, values, objects, properties, and functions beyond those described in this specification. In particular, a conforming implementation of ECMAScript may 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 may support program and regular expression syntax not described in this specification. In particular, a conforming implementation of ECMAScript may support program syntax that makes use of the “future reserved words” listed in subclause 11.6.2.2 of this specification. A conforming implementation of ECMAScript must not implement any extension that is listed as a Forbidden Extension in subclause 16.2 .

3 Normative References # 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 10646:2003: Information Technology – Universal Multiple-Octet Coded Character Set (UCS) plus Amendment 1:2005, Amendment 2:2006, Amendment 3:2008, and Amendment 4:2008, plus additional amendments and corrigenda, or successor ECMA-402, ECMAScript 2015 Internationalization API Specification.

http://www.ecma-international.org/publications/standards/Ecma-402.htm ECMA-404, The JSON Data Interchange Format.

http://www.ecma-international.org/publications/standards/Ecma-404.htm

4 Overview # 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 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. ECMAScript was originally designed to be used as a scripting language, but has become widely used as a general purpose programming language. A scripting language is a programming language that is used to manipulate, customize, 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 is now used to provide core scripting capabilities for a variety of host environments. Therefore the core language is specified in this document apart from any particular host environment. ECMAScript usage has moved beyond simple scripting and it is now used for the full spectrum of programming tasks in many different environments and scales. As the usage of ECMAScript has expanded, so has the features and facilities it provides. ECMAScript is now a fully featured general propose programming language. Some of the facilities of ECMAScript are similar to those used in other programming languages; in particular C, Java™, Self, and Scheme as described in: ISO/IEC 9899:1996, Programming Languages – C. 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 Web Scripting # 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 customized 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 ECMAScript Overview # 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. In ECMAScript, an object is a collection of zero or more properties each with 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 assign a different value to 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, String, and Symbol; an object is a member of the built-in type Object; and a function is a callable object. A function that is associated with an object via a property is called 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 ; objects that are fundamental to the runtime semantics of the language including Object , Function , Boolean , Symbol , and various Error objects; objects that represent and manipulate numeric values including Math , Number , and Date ; the text processing objects String and RegExp ; objects that are indexed collections of values including Array and nine different kinds of Typed Arrays whose elements all have a specific numeric data representation; keyed collections including Map and Set objects; objects supporting structured data including the JSON object, ArrayBuffer , and DataView ; objects supporting control abstractions including generator functions and Promise objects; and, reflection objects including Proxy and Reflect . 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. Large ECMAScript programs are supported by modules which allow a program to be divided into multiple sequences of statements and declarations. Each module explicitly identifies declarations it uses that need to be provided by other modules and which of its declarations are available for use by other modules. 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 Objects # Even though ECMAScript includes syntax for class definitions, ECMAScript objects are not fundamentally class-based 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 initializes 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, while 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 most 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 . Although ECMAScript objects are not inherently class-based, it is often convenient to define class-like abstractions based upon a common pattern of constructor functions, prototype objects, and methods. The ECMAScript built-in objects themselves follow such a class-like pattern. Beginning with ECMAScript 2015, the ECMAScript language includes syntactic class definitions that permit programmers to concisely define objects that conform to the same class-like abstraction pattern used by the built-in objects. 4.2.2 The Strict Variant of ECMAScript # The ECMAScript Language recognizes 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 source text units. Because strict mode is selected at the level of a syntactic source text unit, strict mode only imposes restrictions that have local effect within such a source text unit. Strict mode does not restrict or modify any aspect of the ECMAScript semantics that must operate consistently across multiple source text units. A complete ECMAScript program may be composed of both strict mode and non-strict mode ECMAScript source text units. In this case, strict mode only applies when actually executing code that is defined within a strict mode source text unit. In order to conform to this specification, an ECMAScript implementation must implement both the full unrestricted ECMAScript language and the strict variant of the ECMAScript language as defined by this specification. In addition, an implementation must support the combination of unrestricted and strict mode source text units into a single composite program. 4.3 Terms and Definitions # For the purposes of this document, the following terms and definitions apply. 4.3.1 type # set of data values as defined in clause 6 of this specification 4.3.2 primitive value # member of one of the types Undefined, Null, Boolean, Number, Symbol, or String as defined in clause 6 Note A primitive value is a datum that is represented directly at the lowest level of the language implementation. 4.3.3 object # 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 constructor # function object that creates and initializes 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 prototype # 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 ordinary object # object that has the default behaviour for the essential internal methods that must be supported by all objects 4.3.7 exotic object # object that does not have the default behaviour for one or more of the essential internal methods Note Any object that is not an ordinary object is an exotic object. 4.3.8 standard object # object whose semantics are defined by this specification 4.3.9 built-in object # object specified and supplied by an ECMAScript implementation Note Standard built-in objects are defined in this specification. An ECMAScript implementation may specify and supply additional kinds of built-in objects. A built-in constructor is a built-in object that is also a constructor. 4.3.10 undefined value # primitive value used when a variable has not been assigned a value 4.3.11 Undefined type # type whose sole value is the undefined value 4.3.12 null value # primitive value that represents the intentional absence of any object value 4.3.13 Null type # type whose sole value is the null value 4.3.14 Boolean value # member of the Boolean type Note There are only two Boolean values, true and false 4.3.15 Boolean type # type consisting of the primitive values true and false 4.3.16 Boolean object # 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 slot whose value is the Boolean value. A Boolean object can be coerced to a Boolean value. 4.3.17 String value # 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.18 String type # set of all possible String values 4.3.19 String object # 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 slot whose value is the String value. A String object can be coerced to a String value by calling the String constructor as a function ( 21.1.1.1 ). 4.3.20 Number value # primitive value corresponding to a double-precision 64-bit binary format IEEE 754-2008 value Note A Number value is a member of the Number type and is a direct representation of a number. 4.3.21 Number type # set of all possible Number values including the special “Not-a-Number” (NaN) value, positive infinity, and negative infinity 4.3.22 Number object # 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 slot whose value is the number value. A Number object can be coerced to a number value by calling the Number constructor as a function ( 20.1.1.1 ). 4.3.23 Infinity # number value that is the positive infinite number value 4.3.24 NaN # number value that is an IEEE 754-2008 “Not-a-Number” value 4.3.25 Symbol value # primitive value that represents a unique, non-String Object property key 4.3.26 Symbol type # set of all possible Symbol values 4.3.27 Symbol object # member of the Object type that is an instance of the standard built-in Symbol constructor 4.3.28 function # member of the Object type that may be invoked as a subroutine Note In addition to its 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.29 built-in function # 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.30 property # part of an object that associates a key (either a String value or a Symbol value) and a value 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.31 method # 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.32 built-in method # 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.33 attribute # internal value that defines some characteristic of a property 4.3.34 own property # property that is directly contained by its object 4.3.35 inherited property # property of an object that is not an own property but is a property (either own or inherited) of the object's prototype 4.4 Organization of This Specification # The remainder of this specification is organized as follows: Clause 5 defines the notational conventions used throughout the specification. Clauses 6-9 define the execution environment within which ECMAScript programs operate. Clauses 10-16 define the actual ECMAScript programming language including its syntactic encoding and the execution semantics of all language features. Clauses 17-26 define the ECMAScript standard library. It includes the definitions of all of the standard objects that are available for use by ECMAScript programs as they execute.

5 Notational Conventions # 5.1 Syntactic and Lexical Grammars # 5.1.1 Context-Free Grammars # 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. A chain production is a production that has exactly one nonterminal symbol on its right-hand side along with zero or more terminal symbols. 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 The Lexical and RegExp Grammars # A lexical grammar for ECMAScript is given in clause 11 . This grammar has as its terminal symbols Unicode code points that conform to the rules for SourceCharacter defined in 10.1 . It defines a set of productions, starting from the goal symbol InputElementDiv , InputElementTemplateTail , or InputElementRegExp , or InputElementRegExpOrTemplateTail , that describe how sequences of such code points 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 ( 11.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 21.2.1 . This grammar also has as its terminal symbols the code points as defined by SourceCharacter . It defines a set of productions, starting from the goal symbol Pattern , that describe how sequences of code points 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 The Numeric String Grammar # 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 7.1.3.1 . Productions of the numeric string grammar are distinguished by having three colons “:::” as punctuation. 5.1.4 The Syntactic Grammar # The syntactic grammar for ECMAScript is given in clauses 11, 12, 13, 14, and 15. 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 two alternative goal symbols Script and Module , that describe how sequences of tokens form syntactically correct independent components of ECMAScript programs. When a stream of code points is to be parsed as an ECMAScript Script or Module , 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 input stream is syntactically in error if the tokens in the stream of input elements cannot be parsed as a single instance of the goal nonterminal ( Script or Module ), 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 12, 13, 14 and 15 is not a complete account of which token sequences are accepted as a correct ECMAScript Script or Module . 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 line terminator character appears in certain “awkward” places. In certain cases in order to avoid ambiguities the syntactic grammar uses generalized productions that permit token sequences that do not form a valid ECMAScript Script or Module . For example, this technique is used for object literals and object destructuring patterns. In such cases a more restrictive supplemental grammar is provided that further restricts the acceptable token sequences. In certain contexts, when explicitly specified, the input elements corresponding to such a production are parsed again using a goal symbol of a supplemental grammar. The input stream is syntactically in error if the tokens in the stream of input elements parsed by a cover grammar cannot be parsed as a single instance of the corresponding supplemental goal symbol, with no tokens left over. 5.1.5 Grammar Notation # Terminal symbols of the lexical, RegExp, and numeric string 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 script exactly as written. All terminal symbol code points specified in this way are to be understood as the appropriate Unicode code points from the Basic Latin range, as opposed to any similar-looking code points from other Unicode ranges. Nonterminal symbols are shown in italic type. The definition of a nonterminal (also called a “production”) 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 : BindingIdentifier Initializer opt is a convenient abbreviation for: VariableDeclaration : BindingIdentifier BindingIdentifier Initializer and that: IterationStatement : for ( LexicalDeclaration Expression opt ; Expression opt ) Statement is a convenient abbreviation for: IterationStatement : for ( LexicalDeclaration ; Expression opt ) Statement for ( LexicalDeclaration Expression ; Expression opt ) Statement which in turn is an abbreviation for: IterationStatement : for ( LexicalDeclaration ; ) Statement for ( LexicalDeclaration ; Expression ) Statement for ( LexicalDeclaration Expression ; ) Statement for ( LexicalDeclaration Expression ; Expression ) Statement so, in this example, the nonterminal IterationStatement actually has four alternative right-hand sides. A production may be parameterized by a subscripted annotation of the form “ [parameters] ”, which may appear as a suffix to the nonterminal symbol defined by the production. “ parameters ” may be either a single name or a comma separated list of names. A parameterized production is shorthand for a set of productions defining all combinations of the parameter names, preceded by an underscore, appended to the parameterized nonterminal symbol. This means that: StatementList [Return] : ReturnStatement ExpressionStatement is a convenient abbreviation for: StatementList : ReturnStatement ExpressionStatement StatementList_Return : ReturnStatement ExpressionStatement and that: StatementList [Return, In] : ReturnStatement ExpressionStatement is an abbreviation for: StatementList : ReturnStatement ExpressionStatement StatementList_Return : ReturnStatement ExpressionStatement StatementList_In : ReturnStatement ExpressionStatement StatementList_Return_In : ReturnStatement ExpressionStatement Multiple parameters produce a combinatory number of productions, not all of which are necessarily referenced in a complete grammar. References to nonterminals on the right-hand side of a production can also be parameterized. For example: StatementList : ReturnStatement ExpressionStatement [In] is equivalent to saying: StatementList : ReturnStatement ExpressionStatement_In A nonterminal reference may have both a parameter list and an “ opt ” suffix. For example: VariableDeclaration : BindingIdentifier Initializer [In] opt is an abbreviation for: VariableDeclaration : BindingIdentifier BindingIdentifier Initializer_In Prefixing a parameter name with “ ? ” on a right-hand side nonterminal reference makes that parameter value dependent upon the occurrence of the parameter name on the reference to the current production's left-hand side symbol. For example: VariableDeclaration [In] : BindingIdentifier Initializer [?In] is an abbreviation for: VariableDeclaration : BindingIdentifier Initializer VariableDeclaration_In : BindingIdentifier Initializer_In If a right-hand side alternative is prefixed with “[+parameter]” that alternative is only available if the named parameter was used in referencing the production's nonterminal symbol. If a right-hand side alternative is prefixed with “[~parameter]” that alternative is only available if the named parameter was not used in referencing the production's nonterminal symbol. This means that: StatementList [Return] : [+Return] ReturnStatement ExpressionStatement is an abbreviation for: StatementList : ExpressionStatement StatementList_Return : ReturnStatement ExpressionStatement and that StatementList [Return] : [~Return] ReturnStatement ExpressionStatement is an abbreviation for: StatementList : ReturnStatement ExpressionStatement StatementList_Return : ExpressionStatement 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 sequence is a member of the given set . The set can be written as a comma separated list of one or two element terminal sequences enclosed in curly brackets. 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. If the set consists of a single terminal the phrase “[lookahead ≠ terminal ]” may be used. 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 script 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 script. When an alternative in a production of the lexical grammar or the numeric string grammar appears to be a multi-code point token, it represents the sequence of code points 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 code points that could replace IdentifierName provided that the same sequence of code points 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 point 5.2 Algorithm Conventions # 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. Algorithms may be explicitly parameterized, in which case the names and usage of the parameters must be provided as part of the algorithm's definition. In order to facilitate their use in multiple parts of this specification, some algorithms, called abstract operations, are named and written in parameterized functional form so that they may be referenced by name from within other algorithms. Abstract operations are typically referenced using a functional application style such as operationName( arg1 , arg2 ). Some abstract operations are treated as polymorphically dispatched methods of class-like specification abstractions. Such method-like abstract operations are typically referenced using a method application style such as someValue .operationName( arg1 , arg2 ). Calls to abstract operations return Completion Records. Abstract operations referenced using the functional application style and the method application style that are prefixed by ? indicate that ReturnIfAbrupt should be applied to the resulting Completion Record . For example, ? operationName() is equivalent to ReturnIfAbrupt (operationName()). Similarly, ? someValue .operationName() is equivalent to ReturnIfAbrupt ( someValue .operationName()). The prefix ! is used to indicate that an abstract operation will never return an abrupt completion and that the resulting Completion Record 's value field should be used in place of the return value of the operation. For example, “Let val be ! operationName()” is equivalent to the following algorithm steps: Let val be operationName(). Assert: val is never an abrupt completion . If val is a Completion Record , let val be val .[[Value]]. Algorithms may be associated with productions of one of the ECMAScript grammars. A production that has multiple alternative definitions will typically have a distinct algorithm for each alternative. When an algorithm is associated with a grammar production, it may reference the terminal and nonterminal symbols of the production alternative as if they were parameters of the algorithm. When used in this manner, nonterminal symbols refer to the actual alternative definition that is matched when parsing the source text. When an algorithm is associated with a production alternative, the alternative is typically shown without any “[ ]” grammar annotations. Such annotations should only affect the syntactic recognition of the alternative and have no effect on the associated semantics for the alternative. Unless explicitly specified otherwise, all chain productions have an implicit definition for every algorithm that might be applied to that production's left-hand side nonterminal. The implicit definition simply reapplies the same algorithm name with the same parameters, if any, to the chain production 's sole right-hand side nonterminal and then returns the result. For example, assume there is a production: Block : { StatementList } but there is no corresponding Evaluation algorithm that is explicitly specified for that production. If in some algorithm there is a statement of the form: “Return the result of evaluating Block ” it is implicit that an Evaluation algorithm exists of the form: Runtime Semantics: Evaluation Block : { StatementList } Return the result of evaluating StatementList . 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. Subsubsubstep Subsubsubsubstep Subsubsubsubsubstep 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 that begins with “Assert:” asserts 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 unless otherwise noted 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 ) produces the absolute value of x , which is - x if x is negative (less than zero) and otherwise is x itself. The mathematical function min ( x1 , x2 , ..., xN ) produces the mathematically smallest of x1 through xN . The mathematical function max ( x1 , x2 , ..., xN ) produces the mathematically largest of x1 through xN . The domain and range of these mathematical functions include +∞ and -∞ . 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 ) produces the largest integer (closest to positive infinity) that is not larger than x . Note floor ( x ) = x -( x modulo 1) . 5.3 Static Semantic Rules # Context-free grammars are not sufficiently powerful to express all the rules that define whether a stream of input elements form a valid ECMAScript Script or Module that may be evaluated. In some situations additional rules are needed that may be expressed using either ECMAScript algorithm conventions or prose requirements. Such rules are always associated with a production of a grammar and are called the static semantics of the production. Static Semantic Rules have names and typically are defined using an algorithm. Named Static Semantic Rules are associated with grammar productions and a production that has multiple alternative definitions will typically have for each alternative a distinct algorithm for each applicable named static semantic rule. Unless otherwise specified every grammar production alternative in this specification implicitly has a definition for a static semantic rule named Contains which takes an argument named symbol whose value is a terminal or nonterminal of the grammar that includes the associated production. The default definition of Contains is: For each terminal and nonterminal grammar symbol, sym , in the definition of this production do If sym is the same grammar symbol as symbol , return true . If sym is a nonterminal, then Let contained be the result of sym Contains symbol . If contained is true , return true . Return false . The above definition is explicitly over-ridden for specific productions. A special kind of static semantic rule is an Early Error Rule . Early error rules define early error conditions (see clause 16 ) that are associated with specific grammar productions. Evaluation of most early error rules are not explicitly invoked within the algorithms of this specification. A conforming implementation must, prior to the first evaluation of a Script or Module , validate all of the early error rules of the productions used to parse that Script or Module . If any of the early error rules are violated the Script or Module is invalid and cannot be evaluated.

16 Error Handling and Language Extensions # An implementation must report most errors at the time the relevant ECMAScript language construct is evaluated. An early error is an error that can be detected and reported prior to the evaluation of any construct in the Script containing the error. The presence of an early error prevents the evaluation of the construct. An implementation must report early errors in a Script as part of parsing that Script in ParseScript . Early errors in a Module are reported at the point when the Module would be evaluated and the Module is never initialized. Early errors in eval code are reported at the time eval is called and prevent evaluation of the eval code. All errors that are not early errors are runtime errors. An implementation must report as an early error any occurrence of a condition that is listed in a “Static Semantics: Early Errors” subclause of this specification. An implementation shall not treat other kinds of errors as early errors even if the compiler can prove that a construct cannot execute without error under any circumstances. An implementation may issue an early warning in such a case, but it should not report the error until the relevant construct is actually executed. An implementation shall report all errors as specified, except for the following: Except as restricted in 16.2 , an implementation may extend Script syntax, Module syntax, and regular expression pattern or flag syntax. To permit this, all operations (such as calling eval , using a regular expression literal, or using the Function or RegExp constructor) that are allowed to throw SyntaxError are permitted to exhibit implementation-defined behaviour instead of throwing SyntaxError when they encounter an implementation-defined extension to the script syntax or regular expression pattern or flag syntax.

, an implementation may extend syntax, syntax, and regular expression pattern or flag syntax. To permit this, all operations (such as calling , using a regular expression literal, or using the or constructor) that are allowed to throw are permitted to exhibit implementation-defined behaviour instead of throwing when they encounter an implementation-defined extension to the script syntax or regular expression pattern or flag syntax. Except as restricted in 16.2 , an implementation may provide additional types, values, objects, properties, and functions beyond those described in this specification. This may cause constructs (such as looking up a variable in the global scope) to have implementation-defined behaviour instead of throwing an error (such as ReferenceError ). An implementation may define behaviour other than throwing RangeError for toFixed , toExponential , and toPrecision when the fractionDigits or precision argument is outside the specified range. 16.1 HostReportErrors ( errorList ) # HostReportErrors is an implementation-defined abstract operation that allows host environments to report parsing errors, early errors, and runtime errors. An implementation of HostReportErrors must complete normally in all cases. The default implementation of HostReportErrors is to do nothing. Note errorList will be a List of ECMAScript language values. If the errors are parsing errors or early errors, these will always be SyntaxError or ReferenceError objects. Runtime errors, however, can be any ECMAScript value. 16.2 Forbidden Extensions # An implementation must not extend this specification in the following ways: Other than as defined in this specification, ECMAScript Function objects defined using syntactic constructors in strict mode code must not be created with own properties named "caller" or "arguments" other than those that are created by applying the AddRestrictedFunctionProperties abstract operation to the function. Such own properties also must not be created for function objects defined using an ArrowFunction , MethodDefinition , GeneratorDeclaration , GeneratorExpression , ClassDeclaration , or ClassExpression regardless of whether the definition is contained in strict mode code . Built-in functions, strict mode functions created using the Function constructor, generator functions created using the Generator constructor, and functions created using the bind method also must not be created with such own properties.

must not be created with own properties named or other than those that are created by applying the abstract operation to the function. Such own properties also must not be created for function objects defined using an , , , , , or regardless of whether the definition is contained in . Built-in functions, strict mode functions created using the constructor, generator functions created using the constructor, and functions created using the method also must not be created with such own properties. If an implementation extends non-strict or built-in function objects with an own property named "caller" the value of that property, as observed using [[Get]] or [[GetOwnProperty]], must not be a strict function object. If it is an accessor property, the function that is the value of the property's [[Get]] attribute must never return a strict function when called.

the value of that property, as observed using [[Get]] or [[GetOwnProperty]], must not be a strict function object. If it is an accessor property, the function that is the value of the property's [[Get]] attribute must never return a strict function when called. The behaviour of the following methods must not be extended except as specified in ECMA-402: Object.prototype.toLocaleString , Array.prototype.toLocaleString , Number.prototype.toLocaleString , Date.prototype.toLocaleDateString , Date.prototype.toLocaleString , Date.prototype.toLocaleTimeString , String.prototype.localeCompare , %TypedArray%.prototype.toLocaleString .

, , , , , , , . The RegExp pattern grammars in 21.2.1 and B.1.4 must not be extended to recognize any of the source characters A-Z or a-z as IdentityEscape [U] when the U grammar parameter is present.

and must not be extended to recognize any of the source characters A-Z or a-z as when the U grammar parameter is present. The Syntactic Grammar must not be extended in any manner that allows the token : to immediate follow source text that matches the BindingIdentifier nonterminal symbol.

to immediate follow source text that matches the nonterminal symbol. When processing strict mode code , the syntax of NumericLiteral must not be extended to include LegacyOctalIntegerLiteral and the syntax of DecimalIntegerLiteral must not be extended to include NonOctalDecimalIntegerLiteral as described in B.1.1 .

, the syntax of must not be extended to include and the syntax of must not be extended to include as described in . TemplateCharacter must not be extended to include LegacyOctalEscapeSequence as defined in B.1.2 .

must not be extended to include as defined in . When processing strict mode code , the extensions defined in B.3.2 , B.3.3 , and B.3.4 must not be supported.

, the extensions defined in , , and must not be supported. When parsing for the Module goal symbol, the lexical grammar extensions defined in B.1.3 must not be supported.

17 ECMAScript Standard Built-in Objects # There are certain built-in objects available whenever an ECMAScript Script or Module begins execution. One, the global object , is part of the lexical environment of the executing program. Others are accessible as initial properties of the global object or indirectly as properties of accessible built-in objects. Unless specified otherwise, a built-in object that is callable as a function is a built-in Function object with the characteristics described in 9.3 . Unless specified otherwise, the [[Extensible]] internal slot of a built-in object initially has the value true . Every built-in Function object has a [[Realm]] internal slot whose value is the Realm Record of the realm for which the object was initially created. Many built-in objects are functions: they can be invoked with arguments. Some of them furthermore are constructors: they are functions intended for use with the new operator. For each built-in function, this specification describes the arguments required by that function and the properties of that function object. For each built-in constructor, this specification furthermore describes properties of the prototype object of that constructor and properties of specific object instances returned by a new expression that invokes that constructor. Unless otherwise specified in the description of a particular function, if a built-in function or constructor is given fewer arguments than the function is specified to require, the function or constructor shall behave exactly as if it had been given sufficient additional arguments, each such argument being the undefined value. Such missing arguments are considered to be “not present” and may be identified in that manner by specification algorithms. In the description of a particular function, the terms “ this value” and “NewTarget” have the meanings given in 9.3 . Unless otherwise specified in the description of a particular function, if a built-in function or constructor described is given more arguments than the function is specified to allow, the extra arguments are evaluated by the call and then ignored by the function. However, an implementation may define implementation specific behaviour relating to such arguments as long as the behaviour is not the throwing of a TypeError exception that is predicated simply on the presence of an extra argument. Note 1 Implementations that add additional capabilities to the set of built-in functions are encouraged to do so by adding new functions rather than adding new parameters to existing functions. Unless otherwise specified every built-in function and every built-in constructor has the Function prototype object, which is the initial value of the expression Function.prototype ( 19.2.3 ), as the value of its [[Prototype]] internal slot. Unless otherwise specified every built-in prototype object has the Object prototype object, which is the initial value of the expression Object.prototype ( 19.1.3 ), as the value of its [[Prototype]] internal slot, except the Object prototype object itself. Built-in function objects that are not identified as constructors do not implement the [[Construct]] internal method unless otherwise specified in the description of a particular function. Unless otherwise specified, each built-in function defined in this specification is created as if by calling the CreateBuiltinFunction abstract operation ( 9.3.3 ). Every built-in Function object, including constructors, has a length property whose value is an integer. Unless otherwise specified, this value is equal to the largest number of named arguments shown in the subclause headings for the function description. Optional parameters (which are indicated with brackets: [ ] ) or rest parameters (which are shown using the form «...name») are not included in the default argument count. Note 2 For example, the function object that is the initial value of the map property of the Array prototype object is described under the subclause heading «Array.prototype.map (callbackFn [ , thisArg])» which shows the two named arguments callbackFn and thisArg, the latter being optional; therefore the value of the length property of that Function object is 1 . Unless otherwise specified, the length property of a built-in Function object has the attributes { [[Writable]]: false , [[Enumerable]]: false , [[Configurable]]: true }. Every built-in Function object, including constructors, that is not identified as an anonymous function has a name property whose value is a String. Unless otherwise specified, this value is the name that is given to the function in this specification. For functions that are specified as properties of objects, the name value is the property name string used to access the function. Functions that are specified as get or set accessor functions of built-in properties have "get " or "set " prepended to the property name string. The value of the name property is explicitly specified for each built-in functions whose property key is a Symbol value. Unless otherwise specified, the name property of a built-in Function object, if it exists, has the attributes { [[Writable]]: false , [[Enumerable]]: false , [[Configurable]]: true }. Every other data property described in clauses 18 through 26 and in Annex B.2 has the attributes { [[Writable]]: true , [[Enumerable]]: false , [[Configurable]]: true } unless otherwise specified. Every accessor property described in clauses 18 through 26 and in Annex B.2 has the attributes { [[Enumerable]]: false , [[Configurable]]: true } unless otherwise specified. If only a get accessor function is described, the set accessor function is the default value, undefined . If only a set accessor is described the get accessor is the default value, undefined .

21 Text Processing # 21.1 String Objects # 21.1.1 The String Constructor # The String constructor is the %String% intrinsic object and the initial value of the String property of the global object . When called as a constructor it creates and initializes a new String object. When String is called as a function rather than as a constructor, it performs a type conversion. The String constructor is designed to be subclassable. It may be used as the value of an extends clause of a class definition. Subclass constructors that intend to inherit the specified String behaviour must include a super call to the String constructor to create and initialize the subclass instance with a [[StringData]] internal slot. 21.1.1.1 String ( value ) # When String is called with argument value , the following steps are taken: If no arguments were passed to this function invocation, let s be "" . Else, If NewTarget is undefined and Type ( value ) is Symbol, return SymbolDescriptiveString ( value ). Let s be ? ToString ( value ). If NewTarget is undefined , return s . Return ? StringCreate ( s , ? GetPrototypeFromConstructor (NewTarget, "%StringPrototype%" )). 21.1.2 Properties of the String Constructor # The value of the [[Prototype]] internal slot of the String constructor is the intrinsic object %FunctionPrototype% . The String constructor has the following properties: 21.1.2.1 String.fromCharCode ( ... codeUnits ) # The String.fromCharCode function may be called with any number of arguments which form the rest parameter codeUnits . The following steps are taken: Let codeUnits be a List containing the arguments passed to this function. Let length be the number of elements in codeUnits . Let elements be a new empty List . Let nextIndex be 0. Repeat while nextIndex < length Let next be codeUnits [ nextIndex ]. Let nextCU be ? ToUint16 ( next ). Append nextCU to the end of elements . Let nextIndex be nextIndex + 1. Return the String value whose elements are, in order, the elements in the List elements . If length is 0, the empty string is returned. The length property of the fromCharCode function is 1. 21.1.2.2 String.fromCodePoint ( ... codePoints ) # The String.fromCodePoint function may be called with any number of arguments which form the rest parameter codePoints . The following steps are taken: Let codePoints be a List containing the arguments passed to this function. Let length be the number of elements in codePoints . Let elements be a new empty List . Let nextIndex be 0. Repeat while nextIndex < length Let next be codePoints [ nextIndex ]. Let nextCP be ? ToNumber ( next ). If SameValue ( nextCP , ToInteger ( nextCP )) is false , throw a RangeError exception. If nextCP < 0 or nextCP > 0x10FFFF, throw a RangeError exception. Append the elements of the UTF16Encoding of nextCP to the end of elements . Let nextIndex be nextIndex + 1. Return the String value whose elements are, in order, the elements in the List elements . If length is 0, the empty string is returned. The length property of the fromCodePoint function is 1. 21.1.2.3 String.prototype # The initial value of String.prototype is the intrinsic object %StringPrototype% . This property has the attributes { [[Writable]]: false , [[Enumerable]]: false , [[Configurable]]: false }. 21.1.2.4 String.raw ( template , ... substitutions ) # The String.raw function may be called with a variable number of arguments. The first argument is template and the remainder of the arguments form the List substitutions . The following steps are taken: Let substitutions be a List consisting of all of the arguments passed to this function, starting with the second argument. If fewer than two arguments were passed, the List is empty. Let numberOfSubstitutions be the number of elements in substitutions . Let cooked be ? ToObject ( template ). Let raw be ? ToObject (? Get ( cooked , "raw" )). Let literalSegments be ? ToLength (? Get ( raw , "length" )). If literalSegments ≤ 0, return the empty string. Let stringElements be a new empty List . Let nextIndex be 0. Repeat Let nextKey be ! ToString ( nextIndex ). Let nextSeg be ? ToString (? Get ( raw , nextKey )). Append in order the code unit elements of nextSeg to the end of stringElements . If nextIndex + 1 = literalSegments , then Return the String value whose code units are, in order, the elements in the List stringElements . If stringElements has no elements, the empty string is returned. If nextIndex < numberOfSubstitutions , let next be substitutions [ nextIndex ]. Else, let next be the empty String. Let nextSub be ? ToString ( next ). Append in order the code unit elements of nextSub to the end of stringElements . Let nextIndex be nextIndex + 1. Note String.raw is intended for use as a tag function of a Tagged Template ( 12.3.7 ). When called as such, the first argument will be a well formed template object and the rest parameter will contain the substitution values. 21.1.3 Properties of the String Prototype Object # The String prototype object is the intrinsic object %StringPrototype% . The String prototype object is an ordinary object. The String prototype is itself a String object; it has a [[StringData]] internal slot with the value "" . The value of the [[Prototype]] internal slot of the String prototype object is the intrinsic object %ObjectPrototype% . Unless explicitly stated otherwise, the methods of the String prototype object defined below are not generic and the this value passed to them must be either a String value or an object that has a [[StringData]] internal slot that has been initialized to a String value. The abstract operation thisStringValue( value ) performs the following steps: If Type ( value ) is String, return value . If Type ( value ) is Object and value has a [[StringData]] internal slot, then Assert: value 's [[StringData]] internal slot is a String value. Return the value of value 's [[StringData]] internal slot. Throw a TypeError exception. The phrase “this String value” within the specification of a method refers to the result returned by calling the abstract operation thisStringValue with the this value of the method invocation passed as the argument. 21.1.3.1 String.prototype.charAt ( pos ) # Note 1 Returns a single element String containing the code unit at index pos in the String value resulting from converting this object to a String. If there is no element at that index, the result is the empty String. The result is a String value, not a String object. If pos is a value of Number type that is an integer, then the result of x.charAt(pos) is equal to the result of x.substring(pos, pos+1) . When the charAt method is called with one argument pos , the following steps are taken: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let position be ? ToInteger ( pos ). Let size be the number of elements in S . If position < 0 or position ≥ size , return the empty String. Return a String of length 1, containing one code unit from S , namely the code unit at index position . Note 2 The charAt function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.2 String.prototype.charCodeAt ( pos ) # Note 1 Returns a Number (a nonnegative integer less than 216) that is the code unit value of the string element at index pos in the String resulting from converting this object to a String. If there is no element at that index, the result is NaN . When the charCodeAt method is called with one argument pos , the following steps are taken: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let position be ? ToInteger ( pos ). Let size be the number of elements in S . If position < 0 or position ≥ size , return NaN . Return a value of Number type, whose value is the code unit value of the element at index position in the String S . Note 2 The charCodeAt function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method. 21.1.3.3 String.prototype.codePointAt ( pos ) # Note 1 Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point value of the UTF-16 encoded code point ( 6.1.4 ) starting at the string element at index pos in the String resulting from converting this object to a String. If there is no element at that index, the result is undefined . If a valid UTF-16 surrogate pair does not begin at pos , the result is the code unit at pos . When the codePointAt method is called with one argument pos , the following steps are taken: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let position be ? ToInteger ( pos ). Let size be the number of elements in S . If position < 0 or position ≥ size , return undefined . Let first be the code unit value of the element at index position in the String S . If first < 0xD800 or first > 0xDBFF or position +1 = size , return first . Let second be the code unit value of the element at index position +1 in the String S . If second < 0xDC00 or second > 0xDFFF, return first . Return UTF16Decode ( first , second ). Note 2 The codePointAt function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method. 21.1.3.4 String.prototype.concat ( ... args ) # Note 1 When the concat method is called it returns a String consisting of the code units of the this object (converted to a String) followed by the code units of each of the arguments converted to a String. The result is a String value, not a String object. When the concat method is called with zero or more arguments, the following steps are taken: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let args be a List whose elements are the arguments passed to this function. Let R be S . Repeat, while args is not empty Remove the first element from args and let next be the value of that element. Let nextString be ? ToString ( next ). Let R be the String value consisting of the code units of the previous value of R followed by the code units of nextString . Return R . The length property of the concat method is 1. Note 2 The concat function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method. 21.1.3.5 String.prototype.constructor # The initial value of String.prototype.constructor is the intrinsic object %String% . 21.1.3.6 String.prototype.endsWith ( searchString [ , endPosition ] ) # The following steps are taken: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let isRegExp be ? IsRegExp ( searchString ). If isRegExp is true , throw a TypeError exception. Let searchStr be ? ToString ( searchString ). Let len be the number of elements in S . If endPosition is undefined , let pos be len , else let pos be ? ToInteger ( endPosition ). Let end be min ( max ( pos , 0), len ). Let searchLength be the number of elements in searchStr . Let start be end - searchLength . If start is less than 0, return false . If the sequence of elements of S starting at start of length searchLength is the same as the full element sequence of searchStr , return true . Otherwise, return false . Note 1 Returns true if the sequence of elements of searchString converted to a String is the same as the corresponding elements of this object (converted to a String) starting at endPosition - length(this). Otherwise returns false . Note 2 Throwing an exception if the first argument is a RegExp is specified in order to allow future editions to define extensions that allow such argument values. Note 3 The endsWith function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.7 String.prototype.includes ( searchString [ , position ] ) # The includes method takes two arguments, searchString and position , and performs the following steps: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let isRegExp be ? IsRegExp ( searchString ). If isRegExp is true , throw a TypeError exception. Let searchStr be ? ToString ( searchString ). Let pos be ? ToInteger ( position ). (If position is undefined , this step produces the value 0.) Let len be the number of elements in S . Let start be min ( max ( pos , 0), len ). Let searchLen be the number of elements in searchStr . If there exists any integer k not smaller than start such that k + searchLen is not greater than len , and for all nonnegative integers j less than searchLen , the code unit at index k + j of S is the same as the code unit at index j of searchStr , return true ; but if there is no such integer k , return false . Note 1 If searchString appears as a substring of the result of converting this object to a String, at one or more indices that are greater than or equal to position , return true ; otherwise, returns false . If position is undefined , 0 is assumed, so as to search all of the String. Note 2 Throwing an exception if the first argument is a RegExp is specified in order to allow future editions to define extensions that allow such argument values. Note 3 The includes function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.8 String.prototype.indexOf ( searchString [ , position ] ) # Note 1 If searchString appears as a substring of the result of converting this object to a String, at one or more indices that are greater than or equal to position , then the smallest such index is returned; otherwise, -1 is returned. If position is undefined , 0 is assumed, so as to search all of the String. The indexOf method takes two arguments, searchString and position , and performs the following steps: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let searchStr be ? ToString ( searchString ). Let pos be ? ToInteger ( position ). (If position is undefined , this step produces the value 0.) Let len be the number of elements in S . Let start be min ( max ( pos , 0), len ). Let searchLen be the number of elements in searchStr . Return the smallest possible integer k not smaller than start such that k + searchLen is not greater than len , and for all nonnegative integers j less than searchLen , the code unit at index k + j of S is the same as the code unit at index j of searchStr ; but if there is no such integer k , return the value -1 . Note 2 The indexOf function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.9 String.prototype.lastIndexOf ( searchString [ , position ] ) # Note 1 If searchString appears as a substring of the result of converting this object to a String at one or more indices that are smaller than or equal to position , then the greatest such index is returned; otherwise, -1 is returned. If position is undefined , the length of the String value is assumed, so as to search all of the String. The lastIndexOf method takes two arguments, searchString and position , and performs the following steps: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let searchStr be ? ToString ( searchString ). Let numPos be ? ToNumber ( position ). (If position is undefined , this step produces the value NaN .) If numPos is NaN , let pos be +∞ ; otherwise, let pos be ToInteger ( numPos ). Let len be the number of elements in S . Let start be min ( max ( pos , 0), len ). Let searchLen be the number of elements in searchStr . Return the largest possible nonnegative integer k not larger than start such that k + searchLen is not greater than len , and for all nonnegative integers j less than searchLen , the code unit at index k + j of S is the same as the code unit at index j of searchStr ; but if there is no such integer k , return the value -1 . Note 2 The lastIndexOf function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.10 String.prototype.localeCompare ( that [ , reserved1 [ , reserved2 ] ] ) # An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the localeCompare method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of the localeCompare method is used. When the localeCompare method is called with argument that , it returns a Number other than NaN that represents the result of a locale-sensitive String comparison of the this value (converted to a String) with that (converted to a String). The two Strings are S and That . The two Strings are compared in an implementation-defined fashion. The result is intended to order String values in the sort order specified by a host default locale, and will be negative, zero, or positive, depending on whether S comes before That in the sort order, the Strings are equal, or S comes after That in the sort order, respectively. Before performing the comparisons, the following steps are performed to prepare the Strings: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let That be ? ToString ( that ). The meaning of the optional second and third parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not assign any other interpretation to those parameter positions. The localeCompare method, if considered as a function of two arguments this and that , is a consistent comparison function (as defined in 22.1.3.25 ) on the set of all Strings. The actual return values are implementation-defined to permit implementers to encode additional information in the value, but the function is required to define a total ordering on all Strings. This function must treat Strings that are canonically equivalent according to the Unicode standard as identical and must return 0 when comparing Strings that are considered canonically equivalent. Note 1 The localeCompare method itself is not directly suitable as an argument to Array.prototype.sort because the latter requires a function of two arguments. Note 2 This function is intended to rely on whatever language-sensitive comparison functionality is available to the ECMAScript environment from the host environment, and to compare according to the rules of the host environment's current locale. However, regardless of the host provided comparison capabilities, this function must treat Strings that are canonically equivalent according to the Unicode standard as identical. It is recommended that this function should not honour Unicode compatibility equivalences or decompositions. For a definition and discussion of canonical equivalence see the Unicode Standard, chapters 2 and 3, as well as Unicode Standard Annex #15, Unicode Normalization Forms (http://www.unicode.org/reports/tr15/) and Unicode Technical Note #5, Canonical Equivalence in Applications (http://www.unicode.org/notes/tn5/). Also see Unicode Technical Standard #10, Unicode Collation Algorithm (http://www.unicode.org/reports/tr10/). Note 3 The localeCompare function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.11 String.prototype.match ( regexp ) # When the match method is called with argument regexp , the following steps are taken: Let O be ? RequireObjectCoercible ( this value). If regexp is neither undefined nor null , then Let matcher be ? GetMethod ( regexp , @@match). If matcher is not undefined , then Return ? Call ( matcher , regexp , « O »). Let S be ? ToString ( O ). Let rx be ? RegExpCreate ( regexp , undefined ). Return ? Invoke ( rx , @@match, « S »). Note The match function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.12 String.prototype.normalize ( [ form ] ) # When the normalize method is called with one argument form , the following steps are taken: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). If form is not provided or form is undefined , let form be "NFC" . Let f be ? ToString ( form ). If f is not one of "NFC" , "NFD" , "NFKC" , or "NFKD" , throw a RangeError exception. Let ns be the String value that is the result of normalizing S into the normalization form named by f as specified in http://www.unicode.org/reports/tr15/tr15-29.html. Return ns . Note The normalize function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method. 21.1.3.13 String.prototype.repeat ( count ) # The following steps are taken: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let n be ? ToInteger ( count ). If n < 0, throw a RangeError exception. If n is +∞ , throw a RangeError exception. Let T be a String value that is made from n copies of S appended together. If n is 0, T is the empty String. Return T . Note 1 This method creates a String consisting of the code units of the this object (converted to String) repeated count times. Note 2 The repeat function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.14 String.prototype.replace ( searchValue , replaceValue ) # When the replace method is called with arguments searchValue and replaceValue , the following steps are taken: Let O be ? RequireObjectCoercible ( this value). If searchValue is neither undefined nor null , then Let replacer be ? GetMethod ( searchValue , @@replace). If replacer is not undefined , then Return ? Call ( replacer , searchValue , « O , replaceValue »). Let string be ? ToString ( O ). Let searchString be ? ToString ( searchValue ). Let functionalReplace be IsCallable ( replaceValue ). If functionalReplace is false , then Let replaceValue be ? ToString ( replaceValue ). Search string for the first occurrence of searchString and let pos be the index within string of the first code unit of the matched substring and let matched be searchString . If no occurrences of searchString were found, return string . If functionalReplace is true , then Let replValue be ? Call ( replaceValue , undefined , « matched , pos , string »). Let replStr be ? ToString ( replValue ). Else, Let captures be a new empty List . Let replStr be GetSubstitution ( matched , string , pos , captures , replaceValue ). Let tailPos be pos + the number of code units in matched . Let newString be the String formed by concatenating the first pos code units of string , replStr , and the trailing substring of string starting at index tailPos . If pos is 0, the first element of the concatenation will be the empty String. Return newString . Note The replace function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.14.1 Runtime Semantics: GetSubstitution( matched , str , position , captures , replacement ) # The abstract operation GetSubstitution performs the following steps: Assert: Type ( matched ) is String. Let matchLength be the number of code units in matched . Assert: Type ( str ) is String. Let stringLength be the number of code units in str . Assert: position is a nonnegative integer. Assert: position ≤ stringLength . Assert: captures is a possibly empty List of Strings. Assert: Type ( replacement ) is String. Let tailPos be position + matchLength . Let m be the number of elements in captures . Let result be a String value derived from replacement by copying code unit elements from replacement to result while performing replacements as specified in Table 46 . These $ replacements are done left-to-right, and, once such a replacement is performed, the new replacement text is not subject to further replacements. Return result . Table 46: Replacement Text Symbol Substitutions Code units Unicode Characters Replacement text 0x0024, 0x0024 $$ $ 0x0024, 0x0026 $& matched 0x0024, 0x0060 $` If position is 0, the replacement is the empty String. Otherwise the replacement is the substring of str that starts at index 0 and whose last code unit is at index position - 1. 0x0024, 0x0027 $' If tailPos ≥ stringLength , the replacement is the empty String. Otherwise the replacement is the substring of str that starts at index tailPos and continues to the end of str . 0x0024, N

Where

0x0031 ≤ N ≤ 0x0039 $n where

n is one of 1 2 3 4 5 6 7 8 9 and $n is not followed by a decimal digit The n th element of captures , where n is a single digit in the range 1 to 9. If n ≤ m and the n th element of captures is undefined , use the empty String instead. If n > m , the result is implementation-defined. 0x0024, N, N

Where

0x0030 ≤ N ≤ 0x0039 $nn where

n is one of 0 1 2 3 4 5 6 7 8 9 The nn th element of captures , where nn is a two-digit decimal number in the range 01 to 99. If nn ≤ m and the nn th element of captures is undefined , use the empty String instead. If nn is 00 or nn > m , the result is implementation-defined. 0x0024 $ in any context that does not match any of the above. $ 21.1.3.15 String.prototype.search ( regexp ) # When the search method is called with argument regexp , the following steps are taken: Let O be ? RequireObjectCoercible ( this value). If regexp is neither undefined nor null , then Let searcher be ? GetMethod ( regexp , @@search). If searcher is not undefined , then Return ? Call ( searcher , regexp , « O »). Let string be ? ToString ( O ). Let rx be ? RegExpCreate ( regexp , undefined ). Return ? Invoke ( rx , @@search, « string »). Note The search function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.16 String.prototype.slice ( start , end ) # The slice method takes two arguments, start and end , and returns a substring of the result of converting this object to a String, starting from index start and running to, but not including, index end (or through the end of the String if end is undefined ). If start is negative, it is treated as sourceLength + start where sourceLength is the length of the String. If end is negative, it is treated as sourceLength + end where sourceLength is the length of the String. The result is a String value, not a String object. The following steps are taken: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let len be the number of elements in S . Let intStart be ? ToInteger ( start ). If end is undefined , let intEnd be len ; else let intEnd be ? ToInteger ( end ). If intStart < 0, let from be max ( len + intStart , 0); otherwise let from be min ( intStart , len ). If intEnd < 0, let to be max ( len + intEnd , 0); otherwise let to be min ( intEnd , len ). Let span be max ( to - from , 0). Return a String value containing span consecutive elements from S beginning with the element at index from . Note The slice function is intentionally generic; it does not require that its this value be a String object. Therefore it can be transferred to other kinds of objects for use as a method. 21.1.3.17 String.prototype.split ( separator , limit ) # Returns an Array object into which substrings of the result of converting this object to a String have been stored. The substrings are determined by searching from left to right for occurrences of separator ; these occurrences are not part of any substring in the returned array, but serve to divide up the String value. The value of separator may be a String of any length or it may be an object, such as an RegExp, that has a @@split method. When the split method is called, the following steps are taken: Let O be ? RequireObjectCoercible ( this value). If separator is neither undefined nor null , then Let splitter be ? GetMethod ( separator , @@split). If splitter is not undefined , then Return ? Call ( splitter , separator , « O , limit »). Let S be ? ToString ( O ). Let A be ArrayCreate (0). Let lengthA be 0. If limit is undefined , let lim be 232-1; else let lim be ? ToUint32 ( limit ). Let s be the number of elements in S . Let p be 0. Let R be ? ToString ( separator ). If lim = 0, return A . If separator is undefined , then Perform ! CreateDataProperty ( A , "0" , S ). Return A . If s = 0, then Let z be SplitMatch ( S , 0, R ). If z is not false , return A . Perform ! CreateDataProperty ( A , "0" , S ). Return A . Let q be p . Repeat, while q ≠ s Let e be SplitMatch ( S , q , R ). If e is false , let q be q +1. Else e is an integer index ≤ s , If e = p , let q be q +1. Else e ≠ p , Let T be a String value equal to the substring of S consisting of the code units at indices p (inclusive) through q (exclusive). Perform ! CreateDataProperty ( A , ! ToString ( lengthA ), T ). Increment lengthA by 1. If lengthA = lim , return A . Let p be e . Let q be p . Let T be a String value equal to the substring of S consisting of the code units at indices p (inclusive) through s (exclusive). Perform ! CreateDataProperty ( A , ! ToString ( lengthA ), T ). Return A . Note 1 The value of separator may be an empty String. In this case, separator does not match the empty substring at the beginning or end of the input String, nor does it match the empty substring at the end of the previous separator match. If separator is the empty String, the String is split up into individual code unit elements; the length of the result array equals the length of the String, and each substring contains one code unit. If the this object is (or converts to) the empty String, the result depends on whether separator can match the empty String. If it can, the result array contains no elements. Otherwise, the result array contains one element, which is the empty String. If separator is undefined , then the result array contains just one String, which is the this value (converted to a String). If limit is not undefined , then the output array is truncated so that it contains no more than limit elements. Note 2 The split function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.17.1 Runtime Semantics: SplitMatch ( S , q , R ) # The abstract operation SplitMatch takes three parameters, a String S , an integer q , and a String R , and performs the following steps in order to return either false or the end index of a match: Assert: Type ( R ) is String. Let r be the number of code units in R . Let s be the number of code units in S . If q + r > s , return false . If there exists an integer i between 0 (inclusive) and r (exclusive) such that the code unit at index q + i of S is different from the code unit at index i of R , return false . Return q + r . 21.1.3.18 String.prototype.startsWith ( searchString [ , position ] ) # The following steps are taken: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let isRegExp be ? IsRegExp ( searchString ). If isRegExp is true , throw a TypeError exception. Let searchStr be ? ToString ( searchString ). Let pos be ? ToInteger ( position ). (If position is undefined , this step produces the value 0.) Let len be the number of elements in S . Let start be min ( max ( pos , 0), len ). Let searchLength be the number of elements in searchStr . If searchLength + start is greater than len , return false . If the sequence of elements of S starting at start of length searchLength is the same as the full element sequence of searchStr , return true . Otherwise, return false . Note 1 This method returns true if the sequence of elements of searchString converted to a String is the same as the corresponding elements of this object (converted to a String) starting at index position . Otherwise returns false . Note 2 Throwing an exception if the first argument is a RegExp is specified in order to allow future editions to define extensions that allow such argument values. Note 3 The startsWith function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.19 String.prototype.substring ( start , end ) # The substring method takes two arguments, start and end , and returns a substring of the result of converting this object to a String, starting from index start and running to, but not including, index end of the String (or through the end of the String if end is undefined ). The result is a String value, not a String object. If either argument is NaN or negative, it is replaced with zero; if either argument is larger than the length of the String, it is replaced with the length of the String. If start is larger than end , they are swapped. The following steps are taken: Let O be ? RequireObjectCoercible ( this value). Let S be ? ToString ( O ). Let len be the number of elements in S . Let intStart be ? ToInteger ( start ). If end is undefined , let intEnd be len ; else let intEnd be ? ToInteger ( end ). Let finalStart be min ( max ( intStart , 0), len ). Let finalEnd be min ( max ( intEnd , 0), len ). Let from be min ( finalStart , finalEnd ). Let to be max ( finalStart , finalEnd ). Return a String whose length is to - from , containing code units from S , namely the code units with indices from through to - 1, in ascending order. Note The substring function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.20 String.prototype.toLocaleLowerCase ( [ reserved1 [ , reserved2 ] ] ) # An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the toLocaleLowerCase method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of the toLocaleLowerCase method is used. This function interprets a String value as a sequence of UTF-16 encoded code points, as described in 6.1.4 . This function works exactly the same as toLowerCase except that its result is intended to yield the correct result for the host environment's current locale, rather than a locale-independent result. There will only be a difference in the few cases (such as Turkish) where the rules for that language conflict with the regular Unicode case mappings. The meaning of the optional parameters to this method are defined in the ECMA-402 specification; implementations that do not include ECMA-402 support must not use those parameter positions for anything else. Note The toLocaleLowerCase function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method. 21.1.3.21 String.prototype.toLocaleUpperCase ([ reserved1 [ , reserved2 ] ] ) # An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the toLocaleUpperCase method as specified in the ECMA-402 specification. If an ECMAScri