Calculate delta in percentage in javascript
<p>I need to calculate delta in percentage. I have come up with this function. Is this the correct one?</p>

<pre><code>var a = 300;
var b = 400;
var res;
res = Math.abs(a - b) / a
</code></pre>

<p>Is there a complete function that has defense against zeros?</p>

<p>Thank you</p>