JavaScript Math Object
JavaScript 的 Math 物件提供許多實用的數學常數和數學計算函數讓你可以直接使用。
Math 物件內建的屬性 (Properties)
Math 物件內建的方法 (Methods)
- Math.abs()
- Math.ceil()
- Math.floor()
- Math.round()
- Math.random()
- Math.max()
- Math.min()
- Math.sin()
- Math.cos()
- Math.tan()
- Math.asin()
- Math.acos()
- Math.atan()
- Math.atan2()
- Math.exp()
- Math.log()
- Math.pow()
- Math.sqrt()
ES6 新增的 Math 方法
Math.trunc(): 去除小數點,只保留整數部分Math.sign(): 回傳數值的正負號 (1, -1, 0, -0, NaN)Math.cbrt(): 計算立方根Math.hypot(): 計算所有參數平方和的平方根 (畢氏定理)