Wednesday, December 21, 2016

Javascript-10-Math object


MATH


  • Math.round;         // returns 3.141592653589793
  • Math.round(4.7);    // returns 5
  • Math.round(4.4);    // returns 4
  • Math.pow(82);      // returns 64
  • Math.sqrt(64);      // returns 8
  • Math.abs(-4.7);     // returns 4.7
  • Math.ceil(4.4);     // returns 5
  • Math.floor(4.7);    // returns 4

MATH Trignometry functions:

noteAngle in radians = Angle in degrees x PI / 180.

Math.sin(x) returns the sine (a value between -1 and 1) of the angle x (given in radians).
  • Math.sin(90 * Math.PI / 180);// returns 1 (the sine of 90 degrees)

Math.cos(x) returns the cos(a value between -1 and 1) of the angle x (given in radians).
  • Math.cos(0 * Math.PI / 180);// returns 1 (the cos of 0 degrees)

Math.min() and Math.max()

Math.min(01503020, -8, -200);  // returns -200
Math.max(01503020, -8, -200);  // returns 150



Math.random()

Math.random() returns a random number between 0 (inclusive),  and 1 (exclusive):
Math.random();     // returns a random number



Math Properties (Constants)

JavaScript provides 8 mathematical constants that can be accessed with the Math object:
  1. Math.E        // returns Euler's number
  2. Math.PI       // returns PI
  3. Math.SQRT2    // returns the square root of 2
  4. Math.SQRT1_2  // returns the square root of 1/2
  5. Math.LN2      // returns the natural logarithm of 2
  6. Math.LN10     // returns the natural logarithm of 10
  7. Math.LOG2E    // returns base 2 logarithm of E
  8. Math.LOG10E   // returns base 10 logarithm of E



No comments:

Post a Comment