The unique global object is created before control enters any execution context.
The global object does not have a [[Construct]] internal method; it is not possible to use the global object as a
constructor with the new
operator.
The global object does not have a [[Call]] internal method; it is not possible to invoke the global object as a function.
The value of the [[Prototype]] internal slot of the global object is implementation-dependent.
In addition to the properties defined in this specification the global object may have additional host defined properties.
This may include a property whose value is the global object itself; for example, in the HTML document object model the
window
property of the global object is the global object itself.
The value of Infinity
is +∞ (see
6.1.6). This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
false }.
The value of NaN
is NaN (see 6.1.6). This
property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false
}.
The value of undefined
is undefined (see
6.1.1). This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
false }.
The eval
function is the %eval% intrinsic object. When the eval
function
is called with one argument x, the following steps are taken:
The abstract operation PerformEval with arguments x, evalRealm, strictCaller, and direct performs the following steps:
eval
. If direct is false ctx will be the execution context for the invocation of the eval function.NOTE The eval code cannot instantiate variable or function bindings in the variable
environment of the calling context that invoked the eval if the calling context is evaluating formal parameter
initializers or if either the code of the calling context or the eval code is strict
code. Instead such bindings are instantiated in a new VariableEnvironment that
is only accessible to the eval code. Bindings introduced by let
, const
, or class
declarations are always instantiated in a new LexicalEnvironment.
When the abstract operation EvalDeclarationInstantiation is called with arguments body, varEnv, lexEnv, and strict the following steps are taken:
eval
will not create a global var declaration that would be shadowed by a global
lexical declaration.eval
will not hoist var declaration over a like-named lexical
declaration.NOTE An alternative version of this algorithm is described in B.3.5.
The isFinite
function is the %isFinite% intrinsic object. When the
isFinite
function is called with one argument x, the following steps are taken:
The isNaN
function is the %isNaN% intrinsic object. When the isNaN
function is called with one argument number, the following steps are taken:
NOTE A reliable way for ECMAScript code to test if a value X
is a NaN is an
expression of the form X !== X
. The result will be true if and only if X
is a
NaN.
The parseFloat
function produces a Number value dictated by interpretation of the contents of the
string argument as a decimal literal.
The parseFloat
function is the %parseFloat% intrinsic object. When the
parseFloat
function is called with one argument string, the following steps are taken:
"-"
, return −0.NOTE parseFloat
may interpret only a leading portion of string as a
Number value; it ignores any code units that cannot be interpreted as part of the notation of an decimal literal, and no
indication is given that any such code units were ignored.
The parseInt
function produces an integer value dictated by interpretation of the contents of the
string argument according to the specified radix. Leading white space in string is ignored.
If radix is undefined or 0, it is assumed to be 10
except when the number begins with the code unit pairs 0x
or 0X
, in which case a radix of 16 is
assumed. If radix is 16, the number may also optionally begin
with the code unit pairs 0x
or 0X
.
The parseInt
function is the %parseInt% intrinsic object. When the
parseInt
function is called, the following steps are taken:
"0x"
or
"0X"
, remove the first two code units from S and let R = 16.NOTE parseInt
may interpret only a leading portion of string as an
integer value; it ignores any code units that cannot be interpreted as part of the notation of an integer, and no
indication is given that any such code units were ignored.
Uniform Resource Identifiers, or URIs, are Strings that identify resources (e.g. web pages or files) and transport protocols by which to access them (e.g. HTTP or FTP) on the Internet. The ECMAScript language itself does not provide any support for using URIs except for functions that encode and decode URIs as described in 18.2.6.2, 18.2.6.3, 18.2.6.4 and 18.2.6.5
NOTE Many implementations of ECMAScript provide additional functions and methods that manipulate web pages; these functions are beyond the scope of this standard.
A URI is composed of a sequence of components separated by component separators. The general form is:
Scheme : First /
Second ;
Third ?
Fourth
where the italicized names represent components and “:
”, “/
”,
“;
” and “?
” are reserved for use as separators. The
encodeURI
and decodeURI
functions are intended to work with complete URIs; they assume that
any reserved code units in the URI are intended to have special meaning and so are not encoded. The
encodeURIComponent
and decodeURIComponent
functions are intended to work with the individual
component parts of a URI; they assume that any reserved code units represent text and so must be encoded so that they
are not interpreted as reserved code units when the component is part of a complete URI.
The following lexical grammar specifies the form of encoded URIs.
;
/
?
:
@
&
=
+
$
,
%
HexDigit HexDigita
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
-
_
.
!
~
*
'
(
)
NOTE The above syntax is based upon RFC 2396 and does not reflect changes introduced by the more recent RFC 3986.
Runtime Semantics
When a code unit to be included in a URI is not listed above or is not intended to have the special meaning sometimes
given to the reserved code units, that code unit must be encoded. The code unit is transformed into its UTF-8 encoding,
with surrogate pairs first converted from UTF-16 to the corresponding code point value. (Note that for code units in the
range [0,127] this results in a single octet with the same value.) The resulting sequence of octets is then transformed
into a String with each octet represented by an escape sequence of the form "%xx"
.
The encoding and escaping process is described by the abstract operation Encode taking two String arguments string and unescapedSet.
"%
XY"
where
XY are two uppercase hexadecimal digits encoding the value of jOctet.The unescaping and decoding process is described by the abstract operation Decode taking two String arguments string and reservedSet.
"%"
, then
"%"
,
"%"
, throw a URIError exception.NOTE This syntax of Uniform Resource Identifiers is based upon RFC 2396 and does not reflect the more recent RFC 3986 which replaces RFC 2396. A formal description and implementation of UTF-8 is given in RFC 3629.
In UTF-8, characters are encoded using sequences of 1 to 6 octets. The only octet of a sequence of one has the higher-order bit set to 0, the remaining 7 bits being used to encode the character value. In a sequence of n octets, n>1, the initial octet has the n higher-order bits set to 1, followed by a bit set to 0. The remaining bits of that octet contain bits from the value of the character to be encoded. The following octets all have the higher-order bit set to 1 and the following bit set to 0, leaving 6 bits in each to contain bits from the character to be encoded. The possible UTF-8 encodings of ECMAScript characters are specified in Table 43.
Code Unit Value | Representation | 1st Octet | 2nd Octet | 3rd Octet | 4th Octet |
---|---|---|---|---|---|
0x0000 - 0x007F |
00000000 0zzzzzzz |
0zzzzzzz |
|||
0x0080 - 0x07FF |
00000yyy yyzzzzzz |
110yyyyy |
10zzzzzz |
||
0x0800 - 0xD7FF |
xxxxyyyy yyzzzzzz | 1110xxxx |
10yyyyyy |
10zzzzzz |
|
0xD800 - 0xDBFF followed by0xDC00 – 0xDFFF |
110110vv vvwwwwxx followed by110111yy yyzzzzzz |
11110uuu |
10uuwwww |
10xxyyyy |
10zzzzzz |
0xD800 - 0xDBFF not followed by0xDC00 – 0xDFFF |
causes URIError |
||||
0xDC00 – 0xDFFF |
causes URIError |
||||
0xE000 - 0xFFFF |
xxxxyyyy yyzzzzzz | 1110xxxx |
10yyyyyy |
10zzzzzz |
Where
uuuuu =
vvvv + 1
to account for the addition of 0x10000 as in Surrogates, section 3.7, of the Unicode Standard.
The range of code unit values 0xD800-0xDFFF is used to encode surrogate pairs; the above transformation combines a UTF-16 surrogate pair into a UTF-32 representation and encodes the resulting 21-bit value in UTF-8. Decoding reconstructs the surrogate pair.
RFC 3629 prohibits the decoding of invalid UTF-8 octet sequences. For example, the invalid sequence C0 80 must not decode into the code unit 0x0000. Implementations of the Decode algorithm are required to throw a URIError when encountering such invalid sequences.
The decodeURI
function computes a new version of a URI in which each escape sequence and UTF-8 encoding of
the sort that might be introduced by the encodeURI
function is replaced with the UTF-16 encoding of the code
points that it represents. Escape sequences that could not have been introduced by encodeURI
are not
replaced.
The decodeURI
function is the %decodeURI% intrinsic object. When the
decodeURI
function is called with one argument encodedURI, the following steps are taken:
"#"
.NOTE The code point "#"
is not decoded from escape sequences even though it is
not a reserved URI code point.
The decodeURIComponent
function computes a new version of a URI in which each escape sequence and UTF-8
encoding of the sort that might be introduced by the encodeURIComponent
function is replaced with the UTF-16
encoding of the code points that it represents.
The decodeURIComponent
function is the %decodeURIComponent% intrinsic object. When
the decodeURIComponent
function is called with one argument encodedURIComponent, the following
steps are taken:
The encodeURI
function computes a new version of a UTF-16 encoded (6.1.4) URI in which each instance of certain code points is replaced
by one, two, three, or four escape sequences representing the UTF-8 encoding of the code points.
The encodeURI
function is the %encodeURI% intrinsic object. When the
encodeURI
function is called with one argument uri, the following steps are
taken:
#
".NOTE The code unit "#"
is not encoded to an escape sequence even though it is
not a reserved or unescaped URI code point.
The encodeURIComponent
function computes a new version of a UTF-16 encoded (6.1.4) URI in which each instance of certain code points is replaced
by one, two, three, or four escape sequences representing the UTF-8 encoding of the code point.
The encodeURIComponent
function is the %encodeURIComponent% intrinsic object. When
the encodeURIComponent
function is called with one argument uriComponent, the
following steps are taken:
See 22.1.1.
See 24.1.2.
See 19.3.1.
See 24.2.2.
See 20.3.2.
See 19.5.1.
See 19.5.5.1.
See 22.2.4.
See 22.2.4.
See 19.2.1.
See 22.2.4.
See 22.2.4.
See 22.2.4.
See 23.1.1.
See 20.1.1.
See 19.1.1.
See 26.2.1.
See 25.4.3.
See 19.5.5.2.
See 19.5.5.3.
See 21.2.3.
See 23.2.1.
See 21.1.1.
See 19.4.1.
See 19.5.5.4.
See 19.5.5.5.
See 22.2.4.
See 22.2.4.
See 22.2.4.
See 22.2.4.
See 19.5.5.6.
See 23.3.1.
See 23.4.
See 24.3.
See 20.2.
See 26.1.