Why can't I assign a variable inside a function in Javascript?
<p>Very new to JS here. When I write PHP I have no problem assigning variables inside a function, but inside a JavaScript function it doesn't work. Why?</p>

<p>example:</p>

<pre><code>function hello() {

var animal = 'Dog';
document.write(animal);

}
</code></pre>
