title: Javascript array : problems with array declaration and access
body: <p>I'm currently working on a little project in order to learn the Js and the OOP. But I have a problem, let me explain the differents steps :</p>
  
  <p>1) My constructor : </p>
  
  <pre><code>function Ammo(ammoId,posX,posY){
      this.id=ammoId;
      this.x=posX;
      this.y=posY;
      $('body').append('&lt;div class="ammo ammo'+this.id+'"&gt;&lt;/div&gt;');
  }
  </code></pre>
  
  <p>2) Prototypes : </p>
  
  <pre><code>Ammo.prototype.position = function(){
      $('.ammo'+this.id).css({
          'top': this.y+"px",
          'left': this.x+"px"
      });
  }
  
  Ammo.prototype.ammomove = function(){
      this.y-=1;
      this.position();
  }
  </code></pre>
  
  <p>3) The call :</p>
  
  <pre><code>ammo=[];
  var a=1;
  function createAmmo(){
      var ammoX=main.x;
      var ammoY=main.y;
      ammo[a] = new Ammo(a, ammoX, ammoY);
      ammo[a].position();
      var animAmmo= setInterval("ammo["+a+"].ammomove()",5);
      a++;
  }
  createAmmo();
  </code></pre>
  
  <p>My program works perfectly. But when i declare my array with this syntax : </p>
  
  <pre><code>var ammo = [];
  </code></pre>
  
  <p>it doesn't work and i have the error "ammo is not defined", whereas this works :</p>
  
  <pre><code>ammo = [];
  </code></pre>
  
  <p>Anybody have an idea ? thx !</p>
  
  <p>EDIT : here is my JsFiddle : <a href="https://jsfiddle.net/seabon/c057f1oj/" rel="nofollow">https://jsfiddle.net/seabon/c057f1oj/</a></p>
  
  <p>Press Space Bar for call createAmmo()</p>