mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-18 21:31:46 +00:00
75 lines
16 KiB
HTML
75 lines
16 KiB
HTML
<!DOCTYPE html><html lang="en-GB-oxendict"><head><meta name="viewport" content="width=device-width, initial-scale=1"><meta charset="utf-8"><meta property="og:image" content="https://tc39.es/ecmarkup/ecma-logo.png"><meta property="og:title" content="ECMAScript® 2026 Language Specification"><meta property="og:description" content="Introduction
|
|
This Ecma Standard defines the ECMAScript 2026 Language. It is the seventeenth edition of the ECMAScript Language Specification. ECMAScript is based on several originating technologies, the most well-known being JavaScript (Netscape) and JScript (Microsoft). The language was invent">
|
|
<link rel="icon" href="../img/favicon.ico">
|
|
<link rel="stylesheet" href="../assets/css/ecmarkup.css"><link rel="stylesheet" href="../assets/css/print.css" media="print">
|
|
|
|
<title>ECMAScript® 2026 Language Specification</title><script src="../assets/js/multipage.js?cache=Wu2V1pj2" defer=""></script><script src="../assets/js/ecmarkup.js?cache=BPFBckdu" defer=""></script><link rel="canonical" href="../#sec-strict-mode-of-ecmascript"></head>
|
|
<body><div id="spec-container"><emu-annex id="sec-strict-mode-of-ecmascript">
|
|
<h1><span class="secnum">Annex C <span class="annex-kind">(informative)</span></span> The Strict Mode of ECMAScript</h1>
|
|
<p><b>The strict mode restriction and exceptions</b></p>
|
|
<ul>
|
|
<li>
|
|
<code>implements</code>, <code>interface</code>, <code>let</code>, <code>package</code>, <code>private</code>, <code>protected</code>, <code>public</code>, <code>static</code>, and <code>yield</code> are <emu-xref href="#sec-keywords-and-reserved-words" id="_ref_17256"><a href="ecmascript-language-lexical-grammar.html#sec-keywords-and-reserved-words">reserved words</a></emu-xref> within <emu-xref href="#sec-strict-mode-code" id="_ref_17257"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref>. (<emu-xref href="#sec-keywords-and-reserved-words" id="_ref_903"><a href="ecmascript-language-lexical-grammar.html#sec-keywords-and-reserved-words">12.7.2</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
A conforming implementation, when processing <emu-xref href="#sec-strict-mode-code" id="_ref_17258"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref>, must disallow instances of the productions <emu-grammar><emu-production name="NumericLiteral" type="lexical" collapsed="" class=" inline">
|
|
<emu-nt><a href="ecmascript-language-lexical-grammar.html#prod-NumericLiteral">NumericLiteral</a></emu-nt> <emu-geq>::</emu-geq> <emu-rhs a="8n96hykg"><emu-nt id="_ref_24877"><a href="ecmascript-language-lexical-grammar.html#prod-LegacyOctalIntegerLiteral">LegacyOctalIntegerLiteral</a></emu-nt></emu-rhs>
|
|
</emu-production>
|
|
</emu-grammar> and <emu-grammar><emu-production name="DecimalIntegerLiteral" type="lexical" collapsed="" class=" inline">
|
|
<emu-nt><a href="ecmascript-language-lexical-grammar.html#prod-DecimalIntegerLiteral">DecimalIntegerLiteral</a></emu-nt> <emu-geq>::</emu-geq> <emu-rhs a="xvklurnl"><emu-nt id="_ref_24878"><a href="ecmascript-language-lexical-grammar.html#prod-NonOctalDecimalIntegerLiteral">NonOctalDecimalIntegerLiteral</a></emu-nt></emu-rhs>
|
|
</emu-production>
|
|
</emu-grammar>.
|
|
</li>
|
|
<li>
|
|
A conforming implementation, when processing <emu-xref href="#sec-strict-mode-code" id="_ref_17259"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref>, must disallow instances of the productions <emu-grammar><emu-production name="EscapeSequence" type="lexical" collapsed="" class=" inline">
|
|
<emu-nt><a href="ecmascript-language-lexical-grammar.html#prod-EscapeSequence">EscapeSequence</a></emu-nt> <emu-geq>::</emu-geq> <emu-rhs a="6mwrfc1u"><emu-nt id="_ref_24879"><a href="ecmascript-language-lexical-grammar.html#prod-LegacyOctalEscapeSequence">LegacyOctalEscapeSequence</a></emu-nt></emu-rhs>
|
|
</emu-production>
|
|
</emu-grammar> and <emu-grammar><emu-production name="EscapeSequence" type="lexical" collapsed="" class=" inline">
|
|
<emu-nt><a href="ecmascript-language-lexical-grammar.html#prod-EscapeSequence">EscapeSequence</a></emu-nt> <emu-geq>::</emu-geq> <emu-rhs a="nv0ui3q7"><emu-nt id="_ref_24880"><a href="ecmascript-language-lexical-grammar.html#prod-NonOctalDecimalEscapeSequence">NonOctalDecimalEscapeSequence</a></emu-nt></emu-rhs>
|
|
</emu-production>
|
|
</emu-grammar>.
|
|
</li>
|
|
<li>
|
|
Assignment to an undeclared identifier or otherwise unresolvable reference does not create a property in the <emu-xref href="#sec-global-object" id="_ref_17260"><a href="global-object.html#sec-global-object">global object</a></emu-xref>. When a simple assignment occurs within <emu-xref href="#sec-strict-mode-code" id="_ref_17261"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref>, its <emu-nt id="_ref_24881"><a href="ecmascript-language-expressions.html#prod-LeftHandSideExpression">LeftHandSideExpression</a></emu-nt> must not evaluate to an unresolvable Reference. If it does a <emu-val>ReferenceError</emu-val> exception is thrown (<emu-xref href="#sec-putvalue" id="_ref_904"><a href="ecmascript-data-types-and-values.html#sec-putvalue">6.2.5.6</a></emu-xref>). The <emu-nt id="_ref_24882"><a href="ecmascript-language-expressions.html#prod-LeftHandSideExpression">LeftHandSideExpression</a></emu-nt> also may not be a reference to a <emu-xref href="#sec-object-type" id="_ref_17262"><a href="ecmascript-data-types-and-values.html#sec-object-type">data property</a></emu-xref> with the attribute value { <var class="field">[[Writable]]</var>: <emu-val>false</emu-val> }, to an <emu-xref href="#sec-object-type" id="_ref_17263"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> with the attribute value { <var class="field">[[Set]]</var>: <emu-val>undefined</emu-val> }, nor to a non-existent property of an object whose <var class="field">[[Extensible]]</var> internal slot is <emu-val>false</emu-val>. In these cases a <code>TypeError</code> exception is thrown (<emu-xref href="#sec-assignment-operators" id="_ref_905"><a href="ecmascript-language-expressions.html#sec-assignment-operators">13.15</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
An <emu-nt id="_ref_24883"><a href="ecmascript-language-expressions.html#prod-IdentifierReference">IdentifierReference</a></emu-nt> with the <emu-xref aoid="StringValue" id="_ref_17264"><a href="ecmascript-language-expressions.html#sec-static-semantics-stringvalue">StringValue</a></emu-xref> <emu-val>"eval"</emu-val> or <emu-val>"arguments"</emu-val> may not appear as the <emu-nt id="_ref_24884"><a href="ecmascript-language-expressions.html#prod-LeftHandSideExpression">LeftHandSideExpression</a></emu-nt> of an Assignment operator (<emu-xref href="#sec-assignment-operators" id="_ref_906"><a href="ecmascript-language-expressions.html#sec-assignment-operators">13.15</a></emu-xref>) or of an <emu-nt id="_ref_24885"><a href="ecmascript-language-expressions.html#prod-UpdateExpression">UpdateExpression</a></emu-nt> (<emu-xref href="#sec-update-expressions" id="_ref_907"><a href="ecmascript-language-expressions.html#sec-update-expressions">13.4</a></emu-xref>) or as the <emu-nt id="_ref_24886"><a href="ecmascript-language-expressions.html#prod-UnaryExpression">UnaryExpression</a></emu-nt> operated upon by a Prefix Increment (<emu-xref href="#sec-prefix-increment-operator" id="_ref_908"><a href="ecmascript-language-expressions.html#sec-prefix-increment-operator">13.4.4</a></emu-xref>) or a Prefix Decrement (<emu-xref href="#sec-prefix-decrement-operator" id="_ref_909"><a href="ecmascript-language-expressions.html#sec-prefix-decrement-operator">13.4.5</a></emu-xref>) operator.
|
|
</li>
|
|
<li>
|
|
Arguments objects for <emu-xref href="#strict-function" id="_ref_17265"><a href="ordinary-and-exotic-objects-behaviours.html#strict-function">strict functions</a></emu-xref> define a non-configurable <emu-xref href="#sec-object-type" id="_ref_17266"><a href="ecmascript-data-types-and-values.html#sec-object-type">accessor property</a></emu-xref> <emu-val>"callee"</emu-val> which throws a <emu-val>TypeError</emu-val> exception on access (<emu-xref href="#sec-createunmappedargumentsobject" id="_ref_910"><a href="ordinary-and-exotic-objects-behaviours.html#sec-createunmappedargumentsobject">10.4.4.6</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
Arguments objects for <emu-xref href="#strict-function" id="_ref_17267"><a href="ordinary-and-exotic-objects-behaviours.html#strict-function">strict functions</a></emu-xref> do not dynamically share their <emu-xref href="#array-index" id="_ref_911"><a href="ecmascript-data-types-and-values.html#array-index">array-indexed</a></emu-xref> property values with the corresponding formal parameter bindings of their functions. (<emu-xref href="#sec-arguments-exotic-objects" id="_ref_912"><a href="ordinary-and-exotic-objects-behaviours.html#sec-arguments-exotic-objects">10.4.4</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
For <emu-xref href="#strict-function" id="_ref_17268"><a href="ordinary-and-exotic-objects-behaviours.html#strict-function">strict functions</a></emu-xref>, if an arguments object is created the binding of the local identifier <code>arguments</code> to the arguments object is immutable and hence may not be the target of an assignment expression. (<emu-xref href="#sec-functiondeclarationinstantiation" id="_ref_913"><a href="ordinary-and-exotic-objects-behaviours.html#sec-functiondeclarationinstantiation">10.2.11</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
It is a <emu-val>SyntaxError</emu-val> if the <emu-xref aoid="StringValue" id="_ref_17269"><a href="ecmascript-language-expressions.html#sec-static-semantics-stringvalue">StringValue</a></emu-xref> of a <emu-nt id="_ref_24887"><a href="ecmascript-language-expressions.html#prod-BindingIdentifier">BindingIdentifier</a></emu-nt> is either <emu-val>"eval"</emu-val> or <emu-val>"arguments"</emu-val> within <emu-xref href="#sec-strict-mode-code" id="_ref_17270"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref> (<emu-xref href="#sec-identifiers-static-semantics-early-errors" id="_ref_914"><a href="ecmascript-language-expressions.html#sec-identifiers-static-semantics-early-errors">13.1.1</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
Strict mode eval code cannot instantiate variables or functions in the variable environment of the caller to eval. Instead, a new variable environment is created and that environment is used for declaration binding instantiation for the eval code (<emu-xref href="#sec-eval-x" id="_ref_915"><a href="global-object.html#sec-eval-x">19.2.1</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
If <emu-val>this</emu-val> is evaluated within <emu-xref href="#sec-strict-mode-code" id="_ref_17271"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref>, then the <emu-val>this</emu-val> value is not coerced to an object. A <emu-val>this</emu-val> value of either <emu-val>undefined</emu-val> or <emu-val>null</emu-val> is not converted to the <emu-xref href="#sec-global-object" id="_ref_17272"><a href="global-object.html#sec-global-object">global object</a></emu-xref> and primitive values are not converted to wrapper objects. The <emu-val>this</emu-val> value passed via a function call (including calls made using <code>Function.prototype.apply</code> and <code>Function.prototype.call</code>) do not coerce the passed <emu-val>this</emu-val> value to an object (<emu-xref href="#sec-ordinarycallbindthis" id="_ref_916"><a href="ordinary-and-exotic-objects-behaviours.html#sec-ordinarycallbindthis">10.2.1.2</a></emu-xref>, <emu-xref href="#sec-function.prototype.apply" id="_ref_917"><a href="fundamental-objects.html#sec-function.prototype.apply">20.2.3.1</a></emu-xref>, <emu-xref href="#sec-function.prototype.call" id="_ref_918"><a href="fundamental-objects.html#sec-function.prototype.call">20.2.3.3</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
When a <code>delete</code> operator occurs within <emu-xref href="#sec-strict-mode-code" id="_ref_17273"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref>, a <emu-val>SyntaxError</emu-val> is thrown if its <emu-nt id="_ref_24888"><a href="ecmascript-language-expressions.html#prod-UnaryExpression">UnaryExpression</a></emu-nt> is a direct reference to a variable, function argument, or function name (<emu-xref href="#sec-delete-operator-static-semantics-early-errors" id="_ref_919"><a href="ecmascript-language-expressions.html#sec-delete-operator-static-semantics-early-errors">13.5.1.1</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
When a <code>delete</code> operator occurs within <emu-xref href="#sec-strict-mode-code" id="_ref_17274"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref>, a <emu-val>TypeError</emu-val> is thrown if the property to be deleted has the attribute { <var class="field">[[Configurable]]</var>: <emu-val>false</emu-val> } or otherwise cannot be deleted (<emu-xref href="#sec-delete-operator-runtime-semantics-evaluation" id="_ref_920"><a href="ecmascript-language-expressions.html#sec-delete-operator-runtime-semantics-evaluation">13.5.1.2</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
<emu-xref href="#sec-strict-mode-code" id="_ref_17275"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">Strict mode code</a></emu-xref> may not include a <emu-nt id="_ref_24889"><a href="ecmascript-language-statements-and-declarations.html#prod-WithStatement">WithStatement</a></emu-nt>. The occurrence of a <emu-nt id="_ref_24890"><a href="ecmascript-language-statements-and-declarations.html#prod-WithStatement">WithStatement</a></emu-nt> in such a context is a <emu-val>SyntaxError</emu-val> (<emu-xref href="#sec-with-statement-static-semantics-early-errors" id="_ref_921"><a href="ecmascript-language-statements-and-declarations.html#sec-with-statement-static-semantics-early-errors">14.11.1</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
It is a <emu-val>SyntaxError</emu-val> if a <emu-nt id="_ref_24891"><a href="ecmascript-language-statements-and-declarations.html#prod-CatchParameter">CatchParameter</a></emu-nt> occurs within <emu-xref href="#sec-strict-mode-code" id="_ref_17276"><a href="ecmascript-language-source-code.html#sec-strict-mode-code">strict mode code</a></emu-xref> and the <emu-xref aoid="BoundNames" id="_ref_17277"><a href="syntax-directed-operations.html#sec-static-semantics-boundnames">BoundNames</a></emu-xref> of <emu-nt id="_ref_24892"><a href="ecmascript-language-statements-and-declarations.html#prod-CatchParameter">CatchParameter</a></emu-nt> contains either <code>eval</code> or <code>arguments</code> (<emu-xref href="#sec-try-statement-static-semantics-early-errors" id="_ref_922"><a href="ecmascript-language-statements-and-declarations.html#sec-try-statement-static-semantics-early-errors">14.15.1</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
It is a <emu-val>SyntaxError</emu-val> if the same <emu-nt id="_ref_24893"><a href="ecmascript-language-expressions.html#prod-BindingIdentifier">BindingIdentifier</a></emu-nt> appears more than once in the <emu-nt id="_ref_24894"><a href="ecmascript-language-functions-and-classes.html#prod-FormalParameters">FormalParameters</a></emu-nt> of a <emu-xref href="#strict-function" id="_ref_17278"><a href="ordinary-and-exotic-objects-behaviours.html#strict-function">strict function</a></emu-xref>. An attempt to create such a function using a Function, Generator, or AsyncFunction <emu-xref href="#constructor" id="_ref_17279"><a href="ecmascript-data-types-and-values.html#constructor">constructor</a></emu-xref> is a <emu-val>SyntaxError</emu-val> (<emu-xref href="#sec-function-definitions-static-semantics-early-errors" id="_ref_923"><a href="ecmascript-language-functions-and-classes.html#sec-function-definitions-static-semantics-early-errors">15.2.1</a></emu-xref>, <emu-xref href="#sec-createdynamicfunction" id="_ref_924"><a href="fundamental-objects.html#sec-createdynamicfunction">20.2.1.1.1</a></emu-xref>).
|
|
</li>
|
|
<li>
|
|
An implementation may not extend, beyond that defined in this specification, the meanings within <emu-xref href="#strict-function" id="_ref_17280"><a href="ordinary-and-exotic-objects-behaviours.html#strict-function">strict functions</a></emu-xref> of properties named <emu-val>"caller"</emu-val> or <emu-val>"arguments"</emu-val> of function instances.
|
|
</li>
|
|
</ul>
|
|
</emu-annex></div></body></html> |