Monday, 12 June 2023

Mostely Used Math Methods In JavaScript || JS Methods

 

In JavaScript, there are numerous mathematical methods available. Here are five commonly used math methods:


1. Math.abs(x): This method returns the absolute (positive) value of a number. For example:


            Math.abs(-5); // returns 5

2. Math.round(x): It rounds a number to the nearest integer. If the decimal part is 0.5 or higher, it rounds up; otherwise, it rounds down. For example:


        Math.round(3.6); // returns 4

3. Math.ceil(x): This method rounds a number up to the nearest integer, regardless of the decimal part. For example:


        Math.ceil(2.3); // returns 3

4. Math.floor(x): It rounds a number down to the nearest integer, regardless of the decimal part. For example:


        Math.floor(4.8); // returns 4

5.Math.random(): This method generates a random floating-point number between 0 and 1 (exclusive). For example, to generate a random integer between 1 and 10, you can use the following formula:


        Math.floor(Math.random() * 10) + 1;

These are just a few examples of commonly used math methods in JavaScript. There are many more available in the `Math` object that provide various functionalities for mathematical operations.


Explain :- 

Certainly! Here are some labels for the most commonly used math methods in JavaScript:


1. Absolute Value:

   - Method: `Math.abs()`

   - Purpose: Returns the absolute (positive) value of a number.


2. Rounding:

   - Method: `Math.round()`

   - Purpose: Rounds a number to the nearest integer.


3. Ceiling:

   - Method: `Math.ceil()`

   - Purpose: Rounds a number up to the nearest integer.


4. Floor:

   - Method: `Math.floor()`

   - Purpose: Rounds a number down to the nearest integer.


5. Random Number:

   - Method: `Math.random()`

   - Purpose: Generates a random floating-point number between 0 and 1.


These labels provide a brief description of the purpose of each method, helping to identify their primary functionalities.

No comments:

Post a Comment

This is me