How to correctly alert my variable
<p>I have a pretty decent understanding of Jquery but decided to dig in inside JavaScript because I have no understanding of "raw" JavaScript. <br/>So here's my problem: on document load my function executes fine and alerts: <b>'Hi my name is John'</b> but on button click it alert's just :<b>'Hi my name is'</b>. My question is why is this happening and how can I solve it? <br/>I know that I can FIX IT by putting my variable INSIDE my function, but is there a way to call my FIRST variable declared outside my function <b>(variable just after script type)</b>?<br>
<br/><a href="http://jsfiddle.net/6nuCx/" rel="nofollow">Fiddle here</a>
<br/>My code:  </p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;

//If I try to call this variable WILL NOT WORK:(

var name ='John'; &lt;--SO HOW CAN I CALL THIS VARIABLE TO MY CLICK FUNCTION?--&gt; 

function displayName(name)
{
//If I put my variable like this WILL WORK fine...
//var name ='John';
alert('Hi I am '+name);

}

//This function works on document load
//displayName(name);
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;!--This doesn't work well if variable is OUTSIDE my function:(--&gt;
&lt;button type="button" onclick="displayName(name)"&gt;Display Name&lt;/button&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
