Confused about javascript / jquery variable scope
<p>The pastPath variable in the code below is confusing me. I normally use C# and MVC which of course means I use HTML, JavaScript, and JQuery along with other associated web / mobile technologies.</p>

<p>When I run this code and click the .moreBtn pastPath reports it is set to the URL as I intended. Yet when I try to use .backBtn to set the URL and force my browser to go back to the previous page, I get either that pastPath is undefined, or that it is set to hello.</p>

<p>I know I am having a problem understanding scope here. I have read articles on JavaScript scope but I am wondering instead if someone can resolve this problem and explain how I get my URL from the first function into the second.</p>

<p>I will read more about scope in JavaScript later but it seems very different to scope in most other languages and I presently don't have time to look into it properly.</p>

<pre><code>$(document).ready(function ()
{
    pastPath = "hello";

    $(".moreBtn").click(function ()
    {
        var controller = $(".moreBtn").data('ctrl');
        var action = $(".moreBtn").data('action');
        loc = GetPathDetails("full"); //This simply returns the part of the URL I need.
        pastPath = loc;
        alert(pastPath);
        var fullPath = loc + "/" + controller + "/" + action;
        window.location = fullPath;
    });

    $(".backBtn").click(function ()
    {
        alert(pastPath);
        //window.location = pastPath;
    });

});
</code></pre>

<p>Thanks for your help.</p>
