Avoid using global variables and functions in Javascript
<p>How to alter the JavaScript code below so that it can avoid exposing the variables and functions to the global scope?</p>

<pre><code>var nMax = 10;
var i = 0;
var step = function(){
                //do stuff
                i += 1;
                if(i &lt; nMax){
                                step();
                }else{
                                alert('finished');
                }
}
step();
</code></pre>

<p>Ideally it would be grateful if the reason behind it could be provided.</p>

<p>Any idea would be very much appreciated!</p>
