Why does console.log(undefined) works sometimes but not others? : <h2>Consider this code:</h2>

<pre><code>function x(){
    console.log(y);
}
x();
var t = x();
console.log(t);
</code></pre>

<p>This will throw an error. But if you comment the first console.log inside the function, it will work and print <code>undefined</code>.</p>

<p>What is the explanation of this behavior.</p>

<p>Thank you.</p>
