title: How does Javascript handle BODMAS?
body: <p>I've been doing a bit of math with Javascript for a project I'm currently working on, and have just stumbled across the following:</p>
  
  <p>I'm calculating an amount of results remaining in a list of results (there's a "Load More" button)</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>if (data.length &gt; startIndex + maxLoadAmount) {
      var loadMoreButton = new LoadButton()
      loadButton.ToLoad = data.length - startIndex + maxLoadAmount;
  
      loadMoreButton.click(function () {
      var amountOfCurrentWidgets = $(this).parent().children('.widget').length;
      this.remove();
          loadChildren(amountOfCurrentWidgets, selector, data, widgetType);
      });
      $(selector).append(loadMoreButton);
  }
  </code></pre>
  
  <p>I was surprised at the result when I ran it!</p>
  
  <p>In a particular test, there are 16 available widgets, and when starting at index 0 with a maximum of 5 displayed, the result is 21.</p>
  
  <p>I tracked this down to javascript performing the subtraction before the addition.
  You can reproduce it in jsfiddle here:
  <a href="http://jsfiddle.net/JamesPattison/3hvr4vsr/" rel="nofollow">http://jsfiddle.net/JamesPattison/3hvr4vsr/</a></p>
  
  <p>The workaround is to surround the addition in brackets, though I guess what i'm really asking is:</p>
  
  <p>Am I going insane?</p>