SyntaxStudy
Sign Up
JavaScript Beginner 1 min read

Numbers & Math

Numbers & Math

JavaScript has one number type for integers and decimals.

Special Values

  • Infinity — dividing by 0
  • NaN — invalid math

Math Object

Math.round(), Math.floor(), Math.ceil(), Math.random(), Math.max(), Math.abs()

Example
(9.99 * 3).toFixed(2);   // '29.97'
Math.floor(4.9);         // 4
Math.random();           // 0.0–0.9999
Math.floor(Math.random()*6)+1; // dice roll