Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>OK, I've studied the <a href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf" rel="nofollow noreferrer">ECMAScript specification (PDF)</a> and I have an explanation which discuses the <a href="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form" rel="nofollow noreferrer">BNF grammar</a>.</p> <p>ECMAScript sources are parsed starting with the main symbol, called <code>Program</code>:</p> <pre><code>Program: SourceElements </code></pre> <p>SourceElements' (recursive) definition is this:</p> <pre><code>SourceElements : SourceElement SourceElements SourceElement </code></pre> <p>The, SourceElement is defined as:</p> <pre><code>SourceElement : Statement FunctionDeclaration </code></pre> <p>What we're interested in is the object literal syntax, so we ignore FunctionDeclaration and look at the Statement symbol:</p> <pre><code>Statement : Block VariableStatement EmptyStatement ExpressionStatement IfStatement IterationStatement ContinueStatement BreakStatement ReturnStatement WithStatement LabelledStatement SwitchStatement ThrowStatement TryStatement </code></pre> <p>I'm not sure if the listing order matters (this is how they are in the spec), but... an object literal is an ExpressionStatement, about which the standards say the following (section 12.4):</p> <blockquote> <p>Note that an ExpressionStatement cannot start with an opening curly brace because that might make it ambiguous with a Block. Also, an ExpressionStatement cannot start with the function keyword because that might make it ambiguous with a FunctionDeclaration.</p> </blockquote> <p>So we may have an expression <strong>at the start of the program</strong>, but it must not start with an opening curly brace (<code>{</code>). That's why the following work OK:</p> <ul> <li><code>({} == false);</code></li> <li><code>alert({} == false);</code></li> <li><code>!{} == false;</code></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload