我是stackoverflow的新手,请你忍受我.我需要在JavaScript中进行数学计算,它总是会返回两个变量之间的差异.在数学中看起来像这样:
a = 10; b = 5; a-b = 5; b-a = -5; |a-b| = 5; /*need this*/ |b-a| = 5; /*need this*/
怎么办?
使用Math.abs()得到绝对值.
Math.abs()
Math.abs(4-5) => 1
Math.abs(4-5)
1