<story><title>Stack Overflow answer explaining JS in the &quot;Wat&quot; talk </title><url>http://stackoverflow.com/a/9033306/63225</url><text></text></story><parent_chain></parent_chain><comment><author>drostie</author><text>Stack Overflow is being stupid and not allowing me to post comments there. What I wanted to post is that the JSFiddle code the original asker links at &lt;a href=&quot;http://jsfiddle.net/fe479/1/&quot; rel=&quot;nofollow&quot;&gt;http://jsfiddle.net/fe479/1/&lt;/a&gt; runs into the problem that ({}) (opening braces inside of parentheses) is not the same as {} (opening braces as the start of a line of code).&lt;p&gt;So when you type out({} + []) you are forcing the {} to be something which it is not when you type {} + []. This is part of the &apos;wat&apos;-ness.&lt;p&gt;The basic idea is half-hearted: JavaScript wants to allow both of these forms:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    if (u)
        v;
    
    if (x) {
        y;
        z;
    }
    &lt;/code&gt;&lt;/pre&gt;
And to do so, two interpretations were made of the opening brace: 1. it is &lt;i&gt;not required&lt;/i&gt; and 2. it can &lt;i&gt;appear anywhere&lt;/i&gt;.&lt;p&gt;This was a wrong move. Real code doesn&apos;t have an opening brace appearing in the middle of nowhere, and real code also tends to be more fragile when it uses the first form rather than the second. (About once every other month at my last job, I&apos;d get called to a coworker&apos;s desk when their modifications to my code weren&apos;t working, and the problem was that they&apos;d added a line to the &quot;if&quot; without adding curly braces. I eventually just adopted the habit that the curly braces are always required, even when you&apos;re only writing one line.)&lt;p&gt;Fortunately in many cases eval() will replicate the full wat-ness of JavaScript. The JSFiddle code should read:&lt;p&gt;&lt;pre&gt;&lt;code&gt;    function out(code) {
        function format(x) {
            return typeof x === &quot;string&quot; ?
                JSON.stringify(x) : x;
        }   
        document.writeln(&apos;&amp;#38;gt;&amp;#38;gt;&amp;#38;gt; &apos; + code);
        document.writeln(format(eval(code)));
    }
    document.writeln(&quot;&amp;#60;pre&amp;#62;&quot;);
    out(&apos;[] + []&apos;);
    out(&apos;[] + {}&apos;);
    out(&apos;{} + []&apos;);
    out(&apos;{} + {}&apos;);
    out(&apos;Array(16).join(&quot;wat&quot; + 1)&apos;);
    out(&apos;Array(16).join(&quot;wat - 1&quot;)&apos;);
    out(&apos;Array(16).join(&quot;wat&quot; - 1) + &quot; Batman!&quot;&apos;);
    document.writeln(&quot;&amp;#60;/pre&amp;#62;&quot;);
&lt;/code&gt;&lt;/pre&gt;
[Also that is the first time I have written document.writeln in many many many years, and I feel a little dirty writing anything involving both document.writeln() and eval().]</text></comment>
<story><title>Stack Overflow answer explaining JS in the &quot;Wat&quot; talk </title><url>http://stackoverflow.com/a/9033306/63225</url><text></text></story><parent_chain></parent_chain><comment><author>gerggerg</author><text>heres some more js Watness&lt;p&gt;&lt;pre&gt;&lt;code&gt;    var a = undefined = 1
    //vs 
    b = undefined = 1
&lt;/code&gt;&lt;/pre&gt;
what happens there?</text></comment>