JavaScript
    About Lesson

    The Math object is a built-in object in JavaScript that has properties and methods for mathematical operations. It’s not a function object, it’s not a constructor for Math objects, they are static (belong to the Math object itself).

     

    Properties of the Math Object

    The Math object has several properties that represent mathematical constants. Here are a few:

    • Math.E: Euler’s number, the base of natural logarithms (approximately 2.718).
    • Math.PI: Ratio of the circumference of a circle to its diameter (approximately 3.14159).
    • Math.SQRT2: Square root of 2 (approximately 1.414).

     

    Methods of the Math Object

    The Math object also has several methods that are used for mathematical operations. Here are a few:

    • Math.abs(x): Returns the absolute value of x.
    • Math.ceil(x): Returns the smallest integer greater than or equal to x.
    • Math.floor(x): Returns the largest integer less than or equal to x.
    • Math.max(x, y, z, ..., n): Returns the number with the highest value.
    • Math.min(x, y, z, ..., n): Returns the number with the lowest value.
    • Math.pow(x, y): Returns the value of x to the power of y.
    • Math.random(): Returns a random number between 0 (inclusive) and 1 (exclusive).
    • Math.round(x): Rounds x to the nearest integer.
    • Math.sqrt(x): Returns the square root of x.

     

    The Math object is a powerful tool in JavaScript, that allows you to perform complex mathematical operations in your code. It’s a fundamental concept that’s widely used in programming, so understanding how it works will greatly enhance your JavaScript coding skills.