5: 7 4 comments description comments can be either single or multi line multi line comments cannot nest because a single line comment can contain any character except a line terminator character and because of the general rule that a token is always as long as possible a single line comment always consists of all characters from the marker to the end of the line however the line terminator at the end of the line is not considered to be part of the single line comment it is recognised separately by the lexical grammar and becomes part of the stream of input elements for the syntactic grammar this point is very important because it implies that the presence or absence of single line comments does not affect the process of automatic semicolon insertion 7 9 comments behave like white space and are discarded except that if a multi line comment contains a line terminator character then the entire comment is considered to be a line terminator for purposes of parsing by the syntactic grammar syntax comment multi line comment single line comment multi line comment multi line comment chars multi line comment chars multi line not asterisk char multi line comment chars post asterisk comment charsopt post asterisk comment chars multi line not forward slash or asterisk char multi line comment chars post asterisk comment charsopt multi line not asterisk char source character but not asterisk multi line not forward slash or asterisk char source character but not forward slash or asterisk single line comment single line comment charsopt single line comment chars single line comment char single line comment charsopt single line comment char source character but not line terminator 23: 8 2 the null type the null type has exactly one value called null 25: 8 4 the string type the string type is the set of all finite ordered sequences of zero or more 16 bit unsigned integer values elements the string type is generally used to represent textual data in a running ecma script program in which case each element in the string is treated as a code point value see section 6 each element is regarded as occupying a position within the sequence these positions are indexed with nonnegative integers the first element if any is at position 0 the next element if any at position 1 and so on the length of a string is the number of elements i e 16 bit values within it the empty string has length zero and therefore contains no elements when a string contains actual textual data each element is considered to be a single utf 16 unit whether or not this is the actual storage format of a string the characters within a string are numbered as though they were represented using utf 16 all operations on strings except as otherwise stated treat them as sequences of undifferentiated 16 bit unsigned integers they do not ensure the resulting string is in normalised form nor do they ensure language sensitive results note the rationale behind these decisions was to keep the implementation of strings as simple and highperforming as possible the intent is that textual data coming into the execution environment from outside e g user input text read from a file or received over the network etc be converted to unicode normalised form c before the running program sees it usually this would occur at the same time incoming text is converted from its original character encoding to unicode and would impose no additional overhead since it is recommended that ecma script source code be in normalised form c string literals are guaranteed to be normalised if source text is guaranteed to be normalised as long as they do not contain any unicode escape sequences 26: 8 5 the number type the number type has exactly 18437736874454810627 that is 264 253 3 values representing the doubleprecision 64 bit format ieee 754 values as specified in the ieee standard for binary floating point arithmetic except that the 9007199254740990 that is 253 2 distinct not a number values of the ieee standard are represented in ecma script as a single special nan value note that the nan value is produced by the program expression nan assuming that the globally defined variable nan has not been altered by program execution in some implementations external code might be able to detect a difference between various non a number values but such behaviour is implementation dependent to ecma script code all nan values are indistinguishable from each other there are two other special values called positive infinity and negative infinity for brevity these values are also referred to for expository purposes by the symbols and respectively note that these two infinite number values are produced by the program expressions infinity or simply infinity and infinity assuming that the globally defined variable infinity has not been altered by program execution the other 18437736874454810624 that is 264 253 values are called the finite numbers half of these are positive numbers and half are negative numbers for every finite positive number there is a corresponding negative number having the same magnitude note that there is both a positive zero and a negative zero for brevity these values are also referred to for expository purposes by the symbols 0 and 0 respectively note that these two zero number values are produced by the program expressions 0 or simply 0 and 0 the 18437736874454810622 that is 264 253 2 finite nonzero values are of two kinds 18428729675200069632 that is 264 254 of them are normalised having the form s m 2e where s is 1 or 1 m is a positive integer less than 253 but not less than 252 and e is an integer ranging from 1074 to 971 inclusive the remaining 9007199254740990 that is 253 2 values are denormalised having the form s m 2e where s is 1 or 1 m is a positive integer less than 252 and e is 1074 note that all the positive and negative integers whose magnitude is no greater than 253 are representable in the number type indeed the integer 0 has two representations 0 and 0 a finite number has an odd significand if it is nonzero and the integer m used to express it in one of the two forms shown above is odd otherwise it has an even significand in this specification the phrase the number value for x where x represents an exact nonzero real mathematical quantity which might even be an irrational number such as means a number value chosen in the following manner consider the set of all finite values of the number type with 0 removed and with two additional values added to it that are not representable in the number type namely 21024 which is 1 253 2971 and 21024 which is 1 253 2971 choose the member of this set that is closest in value to x if two values of the set are equally close then the one with an even significand is chosen for this purpose the two extra values 21024 and 21024 are considered to have even significands finally if 21024 was chosen replace it with if 21024 was chosen replace it with if 0 was chosen replace it with 0 if and only if x is less than zero any other chosen value is used unchanged the result is the number value for x this procedure corresponds exactly to the behaviour of the ieee 754 round to nearest mode some ecma script operators deal only with integers in the range 231 through 231 1 inclusive or in the range 0 through 232 1 inclusive these operators accept any value of the number type but first convert each such value to one of 232 integer values see the descriptions of the to int32 and to uint32 operators in sections 0 and 0 respectively 27: 8 6 the object type an object is an unordered collection of properties each property consists of a name a value and a set of attributes 30: 8 6 2 1 get p when the get method of o is called with property name p the following steps are taken 1 if o doesn t have a property with name p go to step 4 2 get the value of the property 3 return result 2 4 if the prototype of o is null return undefined 5 call the get method of prototype with property name p 6 return result 5 38: 8 7 2 put value v w 1 if type v is not reference throw a reference error exception 2 call get base v 3 if result 2 is null go to step 6 4 call the put method of result 2 passing get property name v for the property name and w for the value 5 return 6 call the put method for the global object passing get property name v for the property name and w for the value 7 return 43: 9 2 to boolean the operator to boolean converts its argument to a value of type boolean according to the following table input type result undefined false null false boolean the result equals the input argument no conversion number the result is false if the argument is 0 0 or nan otherwise the result is true string the result is false if the argument is the empty string its length is zero otherwise the result is true object true 50: 9 8 to string the operator to string converts its argument to a value of type string according to the following table input type result undefined undefined null null boolean if the argument is true then the result is true if the argument is false then the result is false number see note below string return the input argument no conversion object apply the following steps call to primitive input argument hint string call to string result 1 return result 2 51: 9 8 1 to string applied to the number type the operator to string converts a number m to string format as follows 1 if m is nan return the string nan 2 if m is 0 or 0 return the string 0 3 if m is less than zero return the string concatenation of the string and to string m 4 if m is infinity return the string infinity 5 otherwise let n k and s be integers such that k 1 10k 1 s 10k the number value for s 10n k is m and k is as small as possible note that k is the number of digits in the decimal representation of s that s is not divisible by 10 and that the least significant digit of s is not necessarily uniquely determined by these criteria 6 if k n 21 return the string consisting of the k digits of the decimal representation of s in order with no leading zeroes followed by n k occurrences of the character 0 7 if 0 n 21 return the string consisting of the most significant n digits of the decimal representation of s followed by a decimal point followed by the remaining k n digits of the decimal representation of s 8 if 6 n 0 return the string consisting of the character 0 followed by a decimal point followed by n occurrences of the character 0 followed by the k digits of the decimal representation of s 9 otherwise if k 1 return the string consisting of the single digit of s followed by lowercase character e followed by a plus sign or minus sign according to whether n 1 is positive or negative followed by the decimal representation of the integer abs n 1 with no leading zeros 10 return the string consisting of the most significant digit of the decimal representation of s followed by a decimal point folloarwed by the remaining k 1 digits of the decimal representation of s followed by the lowercase character e followed by a plus sign or minus sign according to whether n 1 is positive or negative followed by the decimal representation of the integer abs n 1 with no leading zeros note the following observations may be useful as guidelines for implementations but are not part of the normative requirements of this standard if x is any number value other than 0 then to number to string x is exactly the same number value as x the least significant digit of s is not always uniquely determined by the requirements listed in step 5 for implementations that provide more accurate conversions than required by the rules above it is recommended that the following alternative version of step 5 be used as a guideline otherwise let n k and s be integers such that k 1 10k 1 s 10k the number value for s 10n k is m and k is as small as possible if there are multiple possibilities for s choose the value of s for which s 10n k is closest in value to m if there are two such possible values of s choose the one that is even note that k is the number of digits in the decimal representation of s and that s is not divisible by 10 implementors of ecma script may find useful the paper and code written by david m gay for binary to decimal conversion of floating point numbers gay david m correctly rounded binary decimal and decimal binary conversions numerical analysis manuscript 90 10 at t bell laboratories murray hill new jersey november 30 1990 available as http cm bell labs com cm cs doc 90 4 10 ps gz associated code available as http cm bell labs com netlib fp dtoa c gz and as http cm belllabs com netlib fp g fmt c gz and may also be found at the various netlib mirror sites 52: 9 9 to object the operator to object converts its argument to a value of type object according to the following table input type result undefined throw a type error exception null throw a type error exception boolean create a new boolean object whose value property is set to the value of the boolean see 15 6 for a description of boolean objects number create a new number object whose value property is set to the value of the number see 15 7 for a description of number objects string create a new string object whose value property is set to the value of the string see 15 5 for a description of string objects object the result is the input argument no conversion 57: 10 1 3 variable instantiation every execution context has associated with it a variable object variables and functions declared in the source text are added as properties of the variable object for function code parameters are added as properties of the variable object which object is used as the variable object and what attributes are used for the properties depends on the type of code but the remainder of the behaviour is generic on entering an execution context the properties are bound to the variable object in the following order for function code for each formal parameter as defined in the formal parameter list create a property of the variable object whose name is the identifier and whose attributes are determined by the type of code the values of the parameters are supplied by the caller as arguments to call if the caller supplies fewer parameter values than there are formal parameters the extra formal parameters have value undefined if two or more formal parameters share the same name hence the same property the corresponding property is given the value that was supplied for the last parameter with this name if the value of this last parameter was not supplied by the caller the value of the corresponding property is undefined for each function declaration in the code in source text order create a property of the variable object whose name is the identifier in the function declaration whose value is the result returned by creating a function object as described in 13 and whose attributes are determined by the type of code if the variable object already has a property with this name replace its value and attributes semantically this step must follow the creation of formal parameter list properties for each variable declaration or variable declaration no in in the code create a property of the variable object whose name is the identifier in the variable declaration or variable declaration no in whose value is undefined and whose attributes are determined by the type of code if there is already a property of the variable object with the name of a declared variable the value of the property and its attributes are not changed semantically this step must follow the creation of the formal parameter list and function declaration properties in particular if a declared variable has the same name as a declared function or formal parameter the variable declaration does not disturb the existing property 60: 10 1 6 activation object when control enters an execution context for function code an object called the activation object is created and associated with the execution context the activation object is initialised with a property with name arguments and attributes dont delete the initial value of this property is the arguments object described below the activation object is then used as the variable object for the purposes of variable instantiation the activation object is purely a specification mechanism it is impossible for an ecma script program to access the activation object it can access members of the activation object but not the activation object itself when the call operation is applied to a reference value whose base object is an activation object null is used as the this value of the call 62: 10 1 8 arguments object when control enters an execution context for function code an arguments object is created and initialised as follows the value of the internal prototype property of the arguments object is the original object prototype object the one that is the initial value of object prototype see 15 2 3 1 a property is created with name callee and property attributes dont enum the initial value of this property is the function object being executed this allows anonymous functions to be recursive a property is created with name length and property attributes dont enum the initial value of this property is the number of actual parameter values supplied by the caller for each non negative integer arg less than the value of the length property a property is created with name to string arg and property attributes dont enum the initial value of this property is the value of the corresponding actual parameter supplied by the caller the first actual parameter value corresponds to arg 0 the second to arg 1 and so on in the case when arg is less than the number of formal parameters for the function object this property shares its value with the corresponding property of the activation object this means that changing this property changes the corresponding property of the activation object and vice versa 65: 10 2 2 eval code when control enters an execution context for eval code the previous active execution context referred to as the calling context is used to determine the scope chain the variable object and the this value if there is no calling context then initialising the scope chain variable instantiation and determination of the this value are performed just as for global code the scope chain is initialised to contain the same objects in the same order as the calling context s scope chain this includes objects added to the calling context s scope chain by with statements and catch clauses variable instantiation is performed using the calling context s variable object and using empty property attributes the this value is the same as the this value of the calling context 66: 10 2 3 function code the scope chain is initialised to contain the activation object followed by the objects in the scope chain stored in the scope property of the function object variable instantiation is performed using the activation object as the variable object and using property attributes dont delete the caller provides the this value if the this value provided by the caller is not an object including the case where it is null then the this value is the global object 77: 11 2 2 the new operator the production new expression new new expression is evaluated as follows 1 evaluate new expression 2 call get value result 1 3 if type result 2 is not object throw a type error exception 4 if result 2 does not implement the internal construct method throw a type error exception 5 call the construct method on result 2 providing no arguments that is an empty list of arguments 6 return result 5 the production member expression new member expression arguments is evaluated as follows 1 evaluate member expression 2 call get value result 1 3 evaluate arguments producing an internal list of argument values 11 2 4 4 if type result 2 is not object throw a type error exception 5 if result 2 does not implement the internal construct method throw a type error exception 6 call the construct method on result 2 providing the list result 3 as the argument values 7 return result 6 78: 11 2 3 function calls the production call expression member expression arguments is evaluated as follows 1 evaluate member expression 2 evaluate arguments producing an internal list of argument values see 11 2 4 3 call get value result 1 4 if type result 3 is not object throw a type error exception 5 if result 3 does not implement the internal call method throw a type error exception 6 if type result 1 is reference result 6 is get base result 1 otherwise result 6 is null 7 if result 6 is an activation object result 7 is null otherwise result 7 is the same as result 6 8 call the call method on result 3 providing result 7 as the this value and providing the list result 2 as the argument values 9 return result 8 the production call expression call expression arguments is evaluated in exactly the same manner except that the contained call expression is evaluated in step 1 note result 8 will never be of type reference if result 3 is a native ecma script object whether calling a host object can return a value of type reference is implementation dependent 82: 11 3 1 postfix increment operator the production postfix expression left hand side expression no line terminator here is evaluated as follows 1 evaluate left hand side expression 2 call get value result 1 3 call to number result 2 4 add the value 1 to result 3 using the same rules as for the operator see 11 6 3 5 call put value result 1 result 4 6 return result 3 83: 11 3 2 postfix decrement operator the production postfix expression left hand side expression no line terminator here is evaluated as follows 1 evaluate left hand side expression 2 call get value result 1 3 call to number result 2 4 subtract the value 1 from result 3 using the same rules as for the operator 11 6 3 5 call put value result 1 result 4 6 return result 3 84: 11 4 unary operators syntax unary expression postfix expression delete unary expression void unary expression typeof unary expression unary expression unary expression unary expression unary expression unary expression unary expression 85: 11 4 1 the delete operator the production unary expression delete unary expression is evaluated as follows 1 evaluate unary expression 2 if type result 1 is not reference return true 3 call get base result 1 4 call get property name result 1 5 call the delete method on result 3 providing result 4 as the property name to delete 6 return result 5 87: 11 4 3 the typeof operator the production unary expression typeof unary expression is evaluated as follows 1 evaluate unary expression 2 if type result 1 is not reference go to step 4 3 if get base result 1 is null return undefined 4 call get value result 1 5 return a string determined by type result 4 according to the following table type result undefined undefined null object boolean boolean number number string string object native and doesn t implement call object object native and implements call function object host implementation dependent 88: 11 4 4 prefix increment operator the production unary expression unary expression is evaluated as follows 1 evaluate unary expression 2 call get value result 1 3 call to number result 2 4 add the value 1 to result 3 using the same rules as for the operator see 11 6 3 5 call put value result 1 result 4 6 return result 4 89: 11 4 5 prefix decrement operator the production unary expression unary expression is evaluated as follows 1 evaluate unary expression 2 call get value result 1 3 call to number result 2 4 subtract the value 1 from result 3 using the same rules as for the operator see 11 6 3 5 call put value result 1 result 4 6 return result 4 91: 11 4 7 unary operator the unary operator converts its operand to number type and then negates it note that negating 0 produces 0 and negating 0 produces 0 the production unary expression unary expression is evaluated as follows 1 evaluate unary expression 2 call get value result 1 3 call to number result 2 4 if result 3 is nan return nan 5 negate result 3 that is compute a number with the same magnitude but opposite sign 6 return result 5 93: 11 4 9 logical not operator the production unary expression unary expression is evaluated as follows 1 evaluate unary expression 2 call get value result 1 3 call to boolean result 2 4 if result 3 is true return false 5 return true 97: 11 5 3 applying the operator the operator yields the remainder of its operands from an implied division the left operand is the dividend and the right operand is the divisor note in c and c the remainder operator accepts only integral operands in ecma script it also accepts floating point operands the result of a floating point remainder operation as computed by the operator is not the same as the remainder operation defined by ieee 754 the ieee 754 remainder operation computes the remainder from a rounding division not a truncating division and so its behaviour is not analogous to that of the usual integer remainder operator instead the ecma script language defines on floatingpoint operations to behave in a manner analogous to that of the java integer remainder operator this may be compared with the c library function fmod the result of a ecma script floating point remainder operation is determined by the rules of ieee arithmetic if either operand is nan the result is nan the sign of the result equals the sign of the dividend if the dividend is an infinity or the divisor is a zero or both the result is nan if the dividend is finite and the divisor is an infinity the result equals the dividend if the dividend is a zero and the divisor is finite the result is the same as the dividend in the remaining cases where neither an infinity nor a zero nor nan is involved the floating point remainder r from a dividend n and a divisor d is defined by the mathematical relation r n d q where q is an integer that is negative only if n d is negative and positive only if n d is positive and whose magnitude is as large as possible without exceeding the magnitude of the true mathematical quotient of n and d 113: 11 8 7 the in operator the production relational expression relational expression in shift expression is evaluated as follows 1 evaluate relational expression 2 call get value result 1 3 evaluate shift expression 4 call get value result 3 5 if result 4 is not an object throw a type error exception 6 call to string result 2 7 call the has property method of result 4 with parameter result 6 8 return result 7 121: 11 10 binary bitwise operators syntax bitwiseand expression equality expression bitwiseand expression equality expression bitwiseand expression no in equality expression no in bitwiseand expression no in equality expression no in bitwisexor expression bitwiseand expression bitwisexor expression bitwiseand expression bitwisexor expression no in bitwiseand expression no in bitwisexor expression no in bitwiseand expression no in bitwiseor expression bitwisexor expression bitwiseor expression bitwisexor expression bitwiseor expression no in bitwisexor expression no in bitwiseor expression no in bitwisexor expression no in semantics the production a a b where is one of the bitwise operators in the productions above is evaluated as follows 1 evaluate a 2 call get value result 1 3 evaluate b 4 call get value result 3 5 call to int32 result 2 6 call to int32 result 4 7 apply the bitwise operator to result 5 and result 6 the result is a signed 32 bit integer 8 return result 7 122: 11 11 binary logical operators syntax logicaland expression bitwiseor expression logicaland expression bitwiseor expression logicaland expression no in bitwiseor expression no in logicaland expression no in bitwiseor expression no in logicalor expression logicaland expression logicalor expression logicaland expression logicalor expression no in logicaland expression no in logicalor expression no in logicaland expression no in semantics the production logicaland expression logicaland expression bitwiseor expression is evaluated as follows 1 evaluate logicaland expression 2 call get value result 1 3 call to boolean result 2 4 if result 3 is false return result 2 5 evaluate bitwiseor expression 6 call get value result 5 7 return result 6 the production logicalor expression logicalor expression logicaland expression is evaluated as follows 1 evaluate logicalor expression 2 call get value result 1 3 call to boolean result 2 4 if result 3 is true return result 2 5 evaluate logicaland expression 6 call get value result 5 7 return result 6 the logicaland expression no in and logicalor expression no in productions are evaluated in the same manner as the logicaland expression and logicalor expression productions except that the contained logicaland expression no in bitwiseor expression no in and logicalor expression no in are evaluated instead of the contained logicaland expression bitwiseor expression and logicalor expression respectively note the value produced by a or operator is not necessarily of type boolean the value produced will always be the value of one of the two operand expressions 129: 12 1 block syntax block statement list statement list statement statement list statement semantics the production block is evaluated as follows 1 return normal empty empty the production block statement list is evaluated as follows 1 evaluate statement list 2 return result 1 the production statement list statement is evaluated as follows 1 evaluate statement 2 if an exception was thrown return throw v empty where v is the exception execution now proceeds as if no exception were thrown 3 return result 1 the production statement list statement list statement is evaluated as follows 1 evaluate statement list 2 if result 1 is an abrupt completion return result 1 3 evaluate statement 4 if an exception was thrown return throw v empty where v is the exception execution now proceeds as if no exception were thrown 5 if result 3 value is empty let v result 1 value otherwise let v result 3 value 6 return result 3 type v result 3 target 131: 12 3 empty statement syntax empty statement semantics the production empty statement is evaluated as follows 1 return normal empty empty 132: 12 4 expression statement syntax expression statement lookahead function expression note that an expression statement cannot start with an opening curly brace because that might make it ambiguous with a block also an expression statement cannot start with the function keyword because that might make it ambiguous with a function declaration semantics the production expression statement lookahead function expression is evaluated as follows 1 evaluate expression 2 call get value result 1 3 return normal result 2 empty 133: 12 5 the if statement syntax if statement if expression statement else statement if expression statement each else for which the choice of associated if is ambiguous shall be associated with the nearest possible if that would otherwise have no corresponding else semantics the production if statement if expression statement else statement is evaluated as follows 1 evaluate expression 2 call get value result 1 3 call to boolean result 2 4 if result 3 is false go to step 7 5 evaluate the first statement 6 return result 5 7 evaluate the second statement 8 return result 7 the production if statement if expression statement is evaluated as follows 1 evaluate expression 2 call get value result 1 3 call to boolean result 2 4 if result 3 is false return normal empty empty 5 evaluate statement 6 return result 5 134: 12 6 iteration statements an iteration statement consists of a header which consists of a keyword and a parenthesised control construct and a body which consists of a statement syntax iteration statement do statement while expression while expression statement for expression no in expression expression statement for var variable declaration list no in expression expression statement for left hand side expression in expression statement for var variable declaration no in in expression statement 138: 12 6 4 the for in statement the production iteration statement for left hand side expression in expression statement is evaluated as follows 1 evaluate the expression 2 call get value result 1 3 call to object result 2 4 let v empty 5 get the name of the next property of result 3 that doesn t have the dont enum attribute if there is no such property go to step 14 6 evaluate the left hand side expression it may be evaluated repeatedly 7 call put value result 6 result 5 8 evaluate statement 9 if result 8 value is not empty let v result 8 value 10 if result 8 type is break and result 8 target is in the current label set go to step 14 11 if result 8 type is continue and result 8 target is in the current label set go to step 5 12 if result 8 is an abrupt completion return result 8 13 go to step 5 14 return normal v empty the production iteration statement for var variable declaration no in in expression statement is evaluated as follows 1 evaluate variable declaration no in 2 evaluate expression 3 call get value result 2 4 call to object result 3 5 let v empty 6 get the name of the next property of result 4 that doesn t have the dont enum attribute if there is no such property go to step 15 7 evaluate result 1 as if it were an identifier see 0 yes it may be evaluated repeatedly 8 call put value result 7 result 6 9 evaluate statement 10 if result 9 value is not empty let v result 9 value 11 if result 9 type is break and result 9 target is in the current label set go to step 15 12 if result 9 type is continue and result 9 target is in the current label set go to step 6 13 if result 8 is an abrupt completion return result 8 14 go to step 6 15 return normal v empty the mechanics of enumerating the properties step 5 in the first algorithm step 6 in the second is implementation dependent the order of enumeration is defined by the object properties of the object being enumerated may be deleted during enumeration if a property that has not yet been visited during enumeration is deleted then it will not be visited if new properties are added to the object being enumerated during enumeration the newly added properties are not guaranteed to be visited in the active enumeration enumerating the properties of an object includes enumerating properties of its prototype and the prototype of the prototype and so on recursively but a property of a prototype is not enumerated if it is shadowed because some previous object in the prototype chain has a property with the same name 141: 12 9 the return statement syntax return statement return no line terminator here expression semantics an ecma script program is considered syntactically incorrect if it contains a return statement that is not within a function body a return statement causes a function to cease execution and return a value to the caller if expression is omitted the return value is undefined otherwise the return value is the value of expression the production return statement return no line terminator here expression is evaluated as 1 if the expression is not present return return undefined empty 2 evaluate expression 3 call get value result 2 4 return return result 3 empty 142: 12 10 the with statement syntax with statement with expression statement description the with statement adds a computed object to the front of the scope chain of the current execution context then executes a statement with this augmented scope chain then restores the scope chain semantics the production with statement with expression statement is evaluated as follows 1 evaluate expression 2 call get value result 1 3 call to object result 2 4 add result 3 to the front of the scope chain 5 evaluate statement using the augmented scope chain from step 4 6 let c be result 5 if an exception was thrown in step 5 let c be throw v empty where v is the exception execution now proceeds as if no exception were thrown 7 remove result 3 from the front of the scope chain 8 return c note no matter how control leaves the embedded statement whether normally or by some form of abrupt completion or exception the scope chain is always restored to its former state 152: 13 2 1 call when the call property for a function object f is called the following steps are taken 1 establish a new execution context using f s formal parameter list the passed arguments list and the this value as described in 10 2 3 2 evaluate f s function body 3 exit the execution context established in step 1 restoring the previous execution context 4 if result 2 type is throw then throw result 2 value 5 if result 2 type is return then return result 2 value 6 result 2 type must be normal return undefined 154: 14 program syntax program source elements source elements source element source elements source element source element statement function declaration semantics the production program source elements is evaluated as follows 1 process source elements for function declarations 2 evaluate source elements 3 return result 2 the production source elements source element is processed for function declarations as follows 1 process source element for function declarations the production source elements source element is evaluated as follows 1 evaluate source element 2 return result 1 the production source elements source elements source element is processed for function declarations as follows 1 process source elements for function declarations 2 process source element for function declarations the production source elements source elements source element is evaluated as follows 1 evaluate source elements 2 if result 1 is an abrupt completion return result 1 3 evaluate source element 4 return result 3 the production source element statement is processed for function declarations by taking no action the production source element statement is evaluated as follows 1 evaluate statement 2 return result 1 the production source element function declaration is processed for function declarations as follows 1 process function declaration for function declarations see clause 13 the production source element function declaration is evaluated as follows 1 return normal empty empty 155: 15 native ecma script objects there are certain built in objects available whenever an ecma script program begins execution one the global object is in the scope chain of the executing program others are accessible as initial properties of the global object unless specified otherwise the class property of a built in object is function if that built in object has a call property or object if that built in object does not have a call property 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 properties of the 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 function or constructor described in this section 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 unless otherwise specified in the description of a particular function if a function or constructor described in this section is given more arguments than the function is specified to allow the behaviour of the function or constructor is undefined in particular an implementation is permitted but not required to throw a type error exception in this case note 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 every built in function and every built in constructor has the function prototype object which is the initial value of the expression function prototype 15 3 2 1 as the value of its internal prototype property every built in prototype object has the object prototype object which is the initial value of the expression object prototype 15 3 2 1 as the value of its internal prototype property except the object prototype object itself none of the built in functions described in this section shall implement the internal construct method unless otherwise specified in the description of a particular function none of the built in functions described in this section shall initially have a prototype property unless otherwise specified in the description of a particular function every built in function object described in this section whether as a constructor an ordinary function or both 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 section headings for the function description including optional parameters note for example the function object that is the initial value of the slice property of the string prototype object is described under the section heading string prototype slice start end which shows the two named arguments start and end therefore the value of the length property of that function object is 2 in every case the length property of a built in function object described in this section has the attributes read only dont delete dont enum and no others every other property described in this section has the attribute dont enum and no others unless otherwise specified 163: 15 1 2 2 parse int string radix the parse int function produces an integer value dictated by interpretation of the contents of the string argument according to the specified radix leading whitespace in the string is ignored if radix is undefined or 0 it is assumed to be 10 except when the number begins with the character pairs 0x or 0x in which case a radix of 16 is assumed any radix 16 number may also optionally begin with the character pairs 0x or 0x when the parse int function is called the following steps are taken 1 call to string string 2 let s be a newly created substring of result 1 consisting of the first character that is not a str white space char and all characters following that character in other words remove leading white space 3 let sign be 1 4 if s is not empty and the first character of s is a minus sign let sign be 1 5 if s is not empty and the first character of s is a plus sign or a minus sign then remove the first character from s 6 let r to int32 radix 7 if r 0 go to step 11 8 if r 2 or r 36 then return nan 9 if r 16 go to step 13 10 go to step 14 11 let r 10 12 if the length of s is at least 1 and the first character of s is 0 then at the implementation s discretion either let r 8 or leave r unchanged 13 if the length of s is at least 2 and the first two characters of s are either 0x or 0x then remove the first two characters from s and let r 16 14 if s contains any character that is not a radix r digit then let z be the substring of s consisting of all characters before the first such character otherwise let z be s 15 if z is empty return nan 16 compute the mathematical integer value that is represented by z in radix r notation using the letters a z and a z for digits with values 10 through 35 however if r is 10 and z contains more than 20 significant digits every significant digit after the 20th may be replaced by a 0 digit at the option of the implementation and if r is not 2 4 8 10 16 or 32 then result 16 may be an implementation dependent approximation to the mathematical integer value that is represented by z in radix r notation 17 compute the number value for result 16 18 return sign result 17 note parse int may interpret only a leading portion of the string as an integer value it ignores any characters that cannot be interpreted as part of the notation of an integer and no indication is given that any such characters were ignored when radix is 0 or undefined and the string s number begins with a 0 digit not followed by an x or x then the implementation may at its discretion interpret the number either as being octal or as being decimal implementations are encouraged to interpret numbers in this case as being decimal 171: 15 1 3 4 encodeuri component uri component the encodeuri component function computes a new version of a uri in which each instance of certain characters is replaced by one two or three escape sequences representing the utf 8 encoding of the character when the encodeuri component function is called with one argument uri component the following steps are taken 1 call to string uri component 2 let unescapeduri component set be a string containing one instance of each character valid in uri unescaped 3 call encode result 1 unescapeduri component set 4 return result 3 177: 15 1 4 5 boolean see 15 6 1 and 15 6 2 178: 15 1 4 6 number see 15 7 1 and 15 7 2 180: 15 1 4 8 reg exp see 15 10 3 and 15 10 4 182: 15 1 4 10 eval error see 15 11 6 1 183: 15 1 4 11 range error see 15 11 6 2 184: 15 1 4 12 reference error see 15 11 6 3 185: 15 1 4 13 syntax error see 15 11 6 4 187: 15 1 4 15 uri error see 15 11 6 6 189: 15 1 5 1 math see 15 8 194: 15 2 2 1 new object value when the object constructor is called with no arguments or with one argument value the following steps are taken 1 if value is not supplied go to step 8 2 if the type of value is not object go to step 5 3 if the value is a native ecma script object do not create a new object but simply return value 4 if the value is a host object then actions are taken and a result is returned in an implementationdepend manner that may depend on the host object 5 if the type of value is string return to object value 6 if the type of value is boolean return to object value 7 if the type of value is number return to object value 8 the argument value was not supplied or its type was null or undefined create a new native ecma script object the prototype property of the newly constructed object is set to the object prototype object the class property of the newly constructed object is set to object the newly constructed object has no value property return the newly created native object 199: 15 2 4 2 object prototype to string when the to string method is called the following steps are taken 1 get the class property of this object 2 compute a string value by concatenating the three strings object result 1 and 3 return result 2 208: 15 3 1 1 function p1 p2 pn body when the function function is called with some arguments p1 p2 pn body where n might be 0 that is there are no p arguments and where body might also not be provided the following steps are taken 1 create and return a new function object as if the function constructor had been called with the same arguments 15 3 2 1 215: 15 3 4 2 function prototype to string an implementation dependent representation of the function is returned this representation has the syntax of a function declaration note in particular that the use and placement of white space line terminators and semicolons within the representation string is implementation dependent the to string function is not generic it throws a type error exception if its this value is not a function object therefore it cannot be transferred to other kinds of objects for use as a method 221: 15 3 5 3 has instance v assume f is a function object when the has instance method of f is called with value v the following steps are taken 1 if v is not an object return false 2 call the get method of f with property name prototype 3 let o be result 2 4 if o is not an object throw a type error exception 5 let v be the value of the prototype property of v 6 if v is null return false 7 if o and v refer to the same object or if they refer to objects joined to each other 13 1 2 return true 8 go to step 5 226: 15 4 2 1 new array item0 item1 this description applies if and only if the array constructor is given no arguments or at least two arguments the prototype property of the newly constructed object is set to the original array prototype object the one that is the initial value of array prototype 15 4 3 1 the class property of the newly constructed object is set to array the length property of the newly constructed object is set to the number of arguments the 0 property of the newly constructed object is set to item0 if supplied the 1 property of the newly constructed object is set to item1 if supplied and in general for as many arguments as there are the k property of the newly constructed object is set to argument k where the first argument is considered to be argument number 0 227: 15 4 2 2 new array len the prototype property of the newly constructed object is set to the original array prototype object the one that is the initial value of array prototype 15 4 3 1 the class property of the newly constructed object is set to array if the argument len is a number and to uint32 len is equal to len then the length property of the newly constructed object is set to to uint32 len if the argument len is a number and to uint32 len is not equal to len a range error exception is thrown if the argument len is not a number then the length property of the newly constructed object is set to 1 and the 0 property of the newly constructed object is set to len 230: 15 4 4 properties of the array prototype object the value of the internal prototype property of the array prototype object is the object prototype object 15 2 3 1 the array prototype object is itself an array its class is array and it has a length property whose initial value is 0 and the special internal put method described in 15 2 3 1 in following descriptions of functions that are properties of the array prototype object the phrase this object refers to the object that is the this value for the invocation of the function it is permitted for the this to be an object for which the value of the internal class property is not array note the array prototype object does not have a value of property of its own however it inherits the value of property from the object prototype object 233: 15 4 4 3 array prototype to locale string the elements of the array are converted to strings using their to locale string methods and these strings are then concatenated separated by occurrences of a separator string that has been derived in an implementation defined locale specific way the result of calling this function is intended to be analogous to the result of to string except that the result of this function is intended to be localespecific the result is calculated as follows 1 call the get method of this object with argument length 2 call to uint32 result 1 3 let separator be the list separator string appropriate for the host environment s current locale this is derived in an implementation defined way 4 call to string separator 5 if result 2 is zero return the empty string 6 call the get method of this object with argument 0 7 if result 6 is undefined or null use the empty string otherwise call to object result 6 to locale string 8 let r be result 7 9 let k be 1 10 if k equals result 2 return r 11 let s be a string value produced by concatenating r and result 4 12 call the get method of this object with argument to string k 13 if result 12 is undefined or null use the empty string otherwise call to object result 12 to locale string 14 let r be a string value produced by concatenating s and result 13 15 increase k by 1 16 go to step 10 the to locale string function is not generic it throws a type error exception if its this value is not an array object therefore it cannot be transferred to other kinds of objects for use as a method note the first parameter to this function is likely to be used in a future version of this standard it is recommended that implementations do not use this parameter position for anything else 261: 15 5 4 6 string prototype concat string1 string2 when the concat method is called with zero or more arguments string1 string2 etc it returns a string consisting of the characters of this object converted to a string followed by the characters of each of string1 string2 etc where each argument is converted to a string the result is a string value not a string object the following steps are taken 1 call to string giving it the this value as its argument 2 let r be result 1 3 get the next argument in the argument list if there are no more arguments go to step 7 4 call to string result 3 5 let r be the string value consisting of the characters in the previous value of r followed by the characters result 4 6 go to step 3 7 return r the length property of the concat method is 1 note 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 263: 15 5 4 8 string prototype last index of search string position if search string appears as a substring of the result of converting this object to a string at one or more positions that are smaller than or equal to position then the index of the greatest such position 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 last index of method takes two arguments search string and position and performs the following steps 1 call to string giving it the this value as its argument 2 call to string search string 3 call to number position if position is undefined this step produces the value nan 4 if result 3 is nan use otherwise call to integer result 3 5 compute the number of characters in result 1 6 compute min max result 4 0 result 5 7 compute the number of characters in the string that is result 2 8 compute the largest possible nonnegative integer k not larger than result 6 such that k result 7 is not greater than result 5 and for all nonnegative integers j less than result 7 the character at position k j of result 1 is the same as the character at position j of result 2 but if there is no such integer k then compute the value 1 9 return result 8 the length property of the last index of method is 1 note the last index of 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 267: 15 5 4 12 string prototype search regexp if regexp is not an object whose class property is reg exp it is replaced with the result of the expression new reg exp regexp let string denote the result of converting the this value to a string the value string is searched from its beginning for an occurrence of the regular expression pattern regexp the result is a number indicating the offset within the string where the pattern matched or 1 if there was no match note 1 this method ignores the last index and global properties of regexp the last index property of regexp is left unchanged note 2 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 268: 15 5 4 13 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 character position start and running to but not including character position end or through the end of the string if end is undefined if start is negative it is treated as source length start where source length is the length of the string if end is negative it is treated as source length end where source length is the length of the string the result is a string value not a string object the following steps are taken 1 call to string giving it the this value as its argument 2 compute the number of characters in result 1 3 call to integer start 4 if end is undefined use result 2 else use to integer end 5 if result 3 is negative use max result 2 result 3 0 else use min result 3 result 2 6 if result 4 is negative use max result 2 result 4 0 else use min result 4 result 2 7 compute max result 6 result 5 0 8 return a string containing result 7 consecutive characters from result 1 beginning with the character at position result 5 the length property of the slice method is 2 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 270: 15 5 4 15 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 character position start and running to but not including character position end of the string or through the end of the string is 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 1 call to string giving it the this value as its argument 2 compute the number of characters in result 1 3 call to integer start 4 if end is undefined use result 2 else use to integer end 5 compute min max result 3 0 result 2 6 compute min max result 4 0 result 2 7 compute min result 5 result 6 8 compute max result 5 result 6 9 return a string whose length is the difference between result 8 and result 7 containing characters from result 1 namely the characters with indices result 7 through result 8 1 in ascending order the length property of the substring method is 2 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 273: 15 5 4 18 string prototype to upper case this function behaves in exactly the same way as string prototype to lower case except that characters are mapped to their uppercase equivalents as specified in the unicode character database note 1 because both to upper case and to lower case have context sensitive behaviour the functions are not symmetrical in other words s to upper case to lower case is not necessarily equal to s to lower case note 2 the to upper case 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 279: 15 6 1 1 boolean value returns a boolean value not a boolean object computed by to boolean value 287: 15 6 4 3 boolean prototype value of returns this boolean value the value of function is not generic it throws a type error exception if its this value is not a boolean object therefore it cannot be transferred to other kinds of objects for use as a method 289: 15 7 number objects 291: 15 7 1 1 number value returns a number value not a number object computed by to number value if value was supplied else returns 0 293: 15 7 2 1 new number value the prototype property of the newly constructed object is set to the original number prototype object the one that is the initial value of number prototype 15 7 3 1 the class property of the newly constructed object is set to number the value property of the newly constructed object is set to to number value if value was supplied else to 0 294: 15 7 3 properties of the number constructor the value of the internal prototype property of the number constructor is the function prototype object 15 3 4 besides the internal properties and the length property whose value is 1 the number constructor has the following property 298: 15 7 3 4 number nan the value of number nan is nan this property has the attributes dont enum dont delete read only 305: 15 7 4 4 number prototype value of returns this number value the value of function is not generic it throws a type error exception if its this value is not a number object therefore it cannot be transferred to other kinds of objects for use as a method 333: 15 8 2 13 pow x y returns an implementation dependent approximation to the result of raising x to the power y if y is nan the result is nan if y is 0 the result is 1 even if x is nan if y is 0 the result is 1 even if x is nan if x is nan and y is nonzero the result is nan if abs x 1 and y is the result is if abs x 1 and y is the result is 0 if abs x 1 and y is the result is nan if abs x 1 and y is the result is nan if abs x 1 and y is the result is 0 if abs x 1 and y is the result is if x is and y 0 the result is if x is and y 0 the result is 0 if x is and y 0 and y is an odd integer the result is if x is and y 0 and y is not an odd integer the result is if x is and y 0 and y is an odd integer the result is 0 if x is and y 0 and y is not an odd integer the result is 0 if x is 0 and y 0 the result is 0 if x is 0 and y 0 the result is if x is 0 and y 0 and y is an odd integer the result is 0 if x is 0 and y 0 and y is not an odd integer the result is 0 if x is 0 and y 0 and y is an odd integer the result is if x is 0 and y 0 and y is not an odd integer the result is if x 0 and x is finite and y is finite and y is not an integer the result is nan 349: 15 9 1 9 local time conversion from utc to local time is defined by local time t t localtza daylight savingta t conversion from local time to utc is defined by utc t t localtza daylight savingta t localtza note that utc local time t is not necessarily always equal to t 351: 15 9 1 11 make time hour min sec ms the operator make time calculates a number of milliseconds from its four arguments which must be ecma script number values this operator functions as follows 1 if hour is not finite or min is not finite or sec is not finite or ms is not finite return nan 2 call to integer hour 3 call to integer min 4 call to integer sec 5 call to integer ms 6 compute result 2 ms per hour result 3 ms per minute result 4 ms per second result 5 performing the arithmetic according to ieee 754 rules that is as if using the ecma script operators and 7 return result 6 356: 15 9 2 1 date year month date hours minutes seconds ms all of the arguments are optional any arguments supplied are accepted but are completely ignored a string is created and returned as if by the expression new date to string 361: 15 9 4 properties of the date constructor the value of the internal prototype property of the date constructor is the function prototype object 15 3 4 besides the internal properties and the length property whose value is 7 the date constructor has the following properties 363: 15 9 4 2 date parse string the parse function applies the to string operator to its argument and interprets the resulting string as a date it returns a number the utc time value corresponding to the date the string may be interpreted as a local time a utc time or a time in some other time zone depending on the contents of the string if x is any date object whose milliseconds amount is zero within a particular implementation of ecma script then all of the following expressions should produce the same numeric value in that implementation if all the properties referenced have their initial values x value of date parse x to string date parse x toutc string however the expression date parse x to locale string is not required to produce the same number value as the preceding three expressions and in general the value produced by date parse is implementation dependent when given any string value that could not be produced in that implementation by the to string or toutc string method 364: 15 9 4 3 date utc year month date hours minutes seconds ms when the utc function is called with fewer than two arguments the behaviour is implementationdepend when the utc function is called with two to seven arguments it computes the date from year month and optionally date hours minutes seconds and ms the following steps are taken 1 call to number year 2 call to number month 3 if date is supplied use to number date else use 1 4 if hours is supplied use to number hours else use 0 5 if minutes is supplied use to number minutes else use 0 6 if seconds is supplied use to number seconds else use 0 7 if ms is supplied use to number ms else use 0 8 if result 1 is not nan and 0 to integer result 1 99 result 8 is 1900 to integer result 1 otherwise result 8 is result 1 9 compute make day result 8 result 2 result 3 10 compute make time result 4 result 5 result 6 result 7 11 return time clip make date result 9 result 10 the length property of the utc function is 7 note the utc function differs from the date constructor in two ways it returns a time value as a number rather than creating a date object and it interprets the arguments in utc rather than as local time 366: 15 9 5 1 date prototype constructor the initial value of date prototype constructor is the built in date constructor 401: 15 9 5 36 date prototype set date date 1 let t be the result of local time this time value 2 call to number date 3 compute make day year from time t month from time t result 2 4 compute utc make date result 3 time within day t 5 set the value property of the this value to time clip result 4 6 return the value of the value property of the this value 402: 15 9 5 37 date prototype setutc date date 1 let t be this time value 2 call to number date 3 compute make day year from time t month from time t result 2 4 compute make date result 3 time within day t 5 set the value property of the this value to time clip result 4 6 return the value of the value property of the this value 419: 15 10 2 8 atom the production atom pattern character evaluates as follows 1 let ch be the character represented by pattern character 2 let a be a one element char set containing the character ch 3 call character set matcher a false and return its matcher result the production atom evaluates as follows 1 let a be the set of all characters except the four line terminator characters lf cr ls or ps 2 call character set matcher a false and return its matcher result the production atom atom escape evaluates by evaluating atom escape to obtain a matcher and returning that matcher the production atom character class evaluates as follows 1 evaluate character class to obtain a char set a and a boolean invert 2 call character set matcher a invert and return its matcher result the production atom disjunction evaluates as follows 1 evaluate disjunction to obtain a matcher m 2 let paren index be the number of left capturing parentheses in the entire regular expression that occur to the left of this production expansion s initial left parenthesis this is the total number of times the atom disjunction production is expanded prior to this production s atom plus the total number of atom disjunction productions enclosing this atom 3 return an internal matcher closure that takes two arguments a state x and a continuation c and performs the following 1 create an internal continuation closure d that takes one state argument y and performs the following 1 let cap be a fresh copy of y s captures internal array 2 let xe be x s end index 3 let ye be y s end index 4 let s be a fresh string whose characters are the characters of input at positions xe inclusive through ye exclusive 5 set cap paren index 1 to s 6 let z be the state ye cap 7 call c z and return its result 2 call m x d and return its result the production atom disjunction evaluates by evaluating disjunction to obtain a matcher and returning that matcher the production atom disjunction evaluates as follows 1 evaluate disjunction to obtain a matcher m 2 return an internal matcher closure that takes two arguments a state x and a continuation c and performs the following 1 let d be a continuation that always returns its state argument as a successful match result 2 call m x d and let r be its result 3 if r is failure return failure 4 let y be r s state 5 let cap be y s captures internal array 6 let xe be x s end index 7 let z be the state xe cap 8 call c z and return its result the production atom disjunction evaluates as follows 1 evaluate disjunction to obtain a matcher m 2 return an internal matcher closure that takes two arguments a state x and a continuation c and performs the following 1 let d be a continuation that always returns its state argument as a successful match result 2 call m x d and let r be its result 3 if r isn t failure return failure 4 call c x and return its result the internal helper function character set matcher takes two arguments a char set a and a boolean flag invert and performs the following 1 return an internal matcher closure that takes two arguments a state x and a continuation c and performs the following 1 let e be x s end index 2 if e input length return failure 3 let c be the character input e 4 let cc be the result of canonicalize c 5 if invert is true go to step 8 6 if there does not exist a member a of set a such that canonicalize a cc then return failure 7 go to step 9 8 if there exists a member a of set a such that canonicalize a cc then return failure 9 let cap be x s captures internal array 10 let y be the state e 1 cap 11 call c y and return its result the internal helper function canonicalize takes a character parameter ch and performs the following 1 if ignore case is false return ch 2 let u be ch converted to upper case as if by calling string prototype to upper case on the one character string ch 3 if u does not consist of a single character return ch 4 let cu be u s character 5 if ch s code point value is greater than or equal to decimal 128 and cu s code point value is less than decimal 128 then return ch 6 return cu informative comments parentheses of the form disjunction serve both to group the components of the disjunction pattern together and to save the result of the match the result can be used either in a backreference followed by a nonzero decimal number referenced in a replace string or returned as part of an array from the regular expression matching function to inhibit the capturing behaviour of parentheses use the form disjunction instead the form disjunction specifies a zero width positive lookahead in order for it to succeed the pattern inside disjunction must match at the current position but the current position is not advanced before matching the sequel if disjunction can match at the current position in several ways only the first one is tried unlike other regular expression operators there is no backtracking into a form this unusual behaviour is inherited from perl this only matters when the disjunction contains capturing parentheses and the sequel of the pattern contains backreferences to those captures for example a exec baaabac matches the empty string immediately after the first b and therefore returns the array aaa to illustrate the lack of backtracking into the lookahead consider a a b 1 exec baaabac this expression returns aba a and not aaaba a the form disjunction specifies a zero width negative lookahead in order for it to succeed the pattern inside disjunction must fail to match at the current position the current position is not advanced before matching the sequel disjunction can contain capturing parentheses but backreferences to them only make sense from within disjunction itself backreferences to these capturing parentheses from elsewhere in the pattern always return undefined because the negative lookahead must fail for the pattern to succeed for example a a b 2c 2 exec baaabaac looks for an a not immediately followed by some positive number n of a s a b another n a s specified by the first 2 and a c the second 2 is outside the negative lookahead so it matches against undefined and therefore always succeeds the whole expression returns the array baaabaac ba undefined abaac in case insignificant matches all characters are implicitly converted to upper case immediately before they are compared however if converting a character to upper case would expand that character into more than one character such as converting u00df into ss then the character is left asis instead the character is also left as is if it is not an ascii character but converting it to upper case would make it into an ascii character this prevents unicode characters such as u0131 and u017f from matching regular expressions such as a z i which are only intended to match ascii letters furthermore if these conversions were allowed then w i would match each of a b h but not i or s 424: 15 10 2 13 character class the production character class lookahead class ranges evaluates by evaluating class ranges to obtain a char set and returning that char set and the boolean false the production character class class ranges evaluates by evaluating class ranges to obtain a char set and returning that char set and the boolean true 425: 15 10 2 14 class ranges the production class ranges empty evaluates by returning the empty char set the production class ranges nonempty class ranges evaluates by evaluating nonempty class ranges to obtain a char set and returning that char set 427: 15 10 2 16 nonempty class ranges no dash the production nonempty class ranges no dash class atom evaluates by evaluating class atom to obtain a char set and returning that char set the production nonempty class ranges no dash class atom no dash nonempty class ranges no dash evaluates as follows 1 evaluate class atom no dash to obtain a char set a 2 evaluate nonempty class ranges no dash to obtain a char set b 3 return the union of char sets a and b the production nonempty class ranges no dash class atom no dash class atom class ranges evaluates as follows 1 evaluate class atom no dash to obtain a char set a 2 evaluate class atom to obtain a char set b 3 evaluate class ranges to obtain a char set c 4 call character range a b and let d be the resulting char set 5 return the union of char sets d and c informative comments class ranges can expand into single class atoms and or ranges of two class atoms separated by dashes in the latter case the class ranges includes all characters between the first class atom and the second class atom inclusive an error occurs if either class atom does not represent a single character for example if one is w or if the first class atom s code point value is greater than the second class atom s code point value even if the pattern ignores case the case of the two ends of a range is significant in determining which characters belong to the range thus for example the pattern e f i matches only the letters e f e and f while the pattern e f i matches all upper and lower case ascii letters as well as the symbols and a character can be treated literally or it can denote a range it is treated literally if it is the first or last character of class ranges the beginning or end limit of a range specification or immediately follows a range specification 430: 15 10 2 19 class escape the production class escape decimal escape evaluates as follows 1 evaluate decimal escape to obtain an escape value e 2 if e is not a character then throw a syntax error exception 3 let ch be e s character 4 return the one element char set containing the character ch the production class escape b evaluates by returning the char set containing the one character bs unicode value 0008 the production class escape character escape evaluates by evaluating character escape to obtain a character and returning a one element char set containing that character the production class escape character class escape evaluates by evaluating character class escape to obtain a char set and returning that char set informative comments a class atom can use any of the escape sequences that are allowed in the rest of the regular expression except for b b and backreferences inside a character class b means the backspace character while b and backreferences raise errors using a backreference inside a class atom causes an error 433: 15 10 4 the reg exp constructor when reg exp is called as part of a new expression it is a constructor it initialises the newly created object 434: 15 10 4 1 new reg exp pattern flags if pattern is an object r whose class property is reg exp and flags is undefined then let p be the pattern used to construct r and let f be the flags used to construct r if pattern is an object r whose class property is reg exp and flags is not undefined then throw a type error exception otherwise let p be the empty string if pattern is undefined and to string pattern otherwise and let f be the empty string if flags is undefined and to string flags otherwise the global property of the newly constructed object is set to a boolean value that is true if f contains the character g and false otherwise the ignore case property of the newly constructed object is set to a boolean value that is true if f contains the character i and false otherwise the multiline property of the newly constructed object is set to a boolean value that is true if f contains the character m and false otherwise if f contains any character other than g i or m or if it contains the same one more than once then throw a syntax error exception if p s characters do not have the form pattern then throw a syntax error exception otherwise let the newly constructed object have a match property obtained by evaluating compiling pattern note that evaluating pattern may throw a syntax error exception note if pattern is a string literal the usual escape sequence substitutions are performed before the string is processed by reg exp if pattern must contain an escape sequence to be recognised by reg exp the character must be escaped within the string literal to prevent its being removed when the contents of the string literal are formed the source property of the newly constructed object is set to an implementation defined string value in the form of a pattern based on p the last index property of the newly constructed object is set to 0 the prototype property of the newly constructed object is set to the original reg exp prototype object the one that is the initial value of reg exp prototype the class property of the newly constructed object is set to reg exp 435: 15 10 5 properties of the reg exp constructor the value of the internal prototype property of the reg exp constructor is the function prototype object 15 3 4 besides the internal properties and the length property whose value is 2 the reg exp constructor has the following properties 448: 15 11 error objects instances of error objects are thrown as exceptions when runtime errors occur the error objects may also serve as base objects for user defined exception classes 453: 15 11 3 properties of the error constructor the value of the internal prototype property of the error constructor is the function prototype object 15 3 4 besides the internal properties and the length property whose value is 1 the error constructor has the following property 456: 15 11 4 1 error prototype constructor the initial value of error prototype constructor is the built in error constructor 461: 15 11 6 native error types used in this standard one of the native error objects below is thrown when a runtime error is detected all of these objects share the same structure as described in 15 11 7 464: 15 11 6 3 reference error indicate that an invalid reference value has been detected see 8 7 1 and 8 7 2 465: 15 11 6 4 syntax error indicates that a parsing error has occurred see 15 1 2 1 15 3 2 1 15 10 2 5 15 10 2 9 15 10 2 15 15 10 2 19 and 15 10 4 1 466: 15 11 6 5 type error indicates the actual type of an operand is different than the expected type see 8 6 2 8 6 2 6 9 9 11 2 2 11 2 3 11 8 6 11 8 7 15 3 4 2 15 3 4 3 15 3 4 4 15 3 5 3 15 4 4 2 15 4 4 3 15 5 4 2 15 5 4 3 15 6 4 15 6 4 2 15 6 4 3 15 7 4 15 7 4 2 15 7 4 4 15 9 5 15 9 5 9 15 9 5 27 15 10 4 1 and 15 10 6 470: 15 11 7 2 native error message the prototype property of the newly constructed object is set to the prototype object for this error constructor the class property of the newly constructed object is set to error if the argument message is not undefined the message property of the newly constructed object is set to to string message 472: 15 11 7 4 new native error message the prototype property of the newly constructed object is set to the prototype object for this native error constructor the class property of the newly constructed object is set to error if the argument message is not undefined the message property of the newly constructed object is set to to string message 473: 15 11 7 5 properties of the native error constructors the value of the internal prototype property of a native error constructor is the function prototype object 15 3 4 besides the internal properties and the length property whose value is 1 each native error constructor has the following property 474: 15 11 7 6 native error prototype the initial value of native error prototype is a native error prototype object 15 11 7 7 each native error constructor has a separate prototype object this property has the attributes dont enum dont delete read only