JavaScript Number Methods You Should Know in 2023

JavaScript Number Methods You Should Know in 2023

Arun R's photo
Arun R
·Feb 18, 2023·

3 min read

Javascript is the most popular and trending technology in the tech world, Javascript has been started as a simple programming language that intends to add a few interactive features to the webpage and now it's become a very powerful programming language that’s used in every website javascript is used in giant web applications like Uber, Facebook, Google maps Etc.., In this article, we will learn about javascript and Basics of Number methods used in Javascript.

Types of Number methods

Math.random() :

Javascript provides a method random called Math. random() returns a random number between 0 with an Inclusive and 1 with an exclusive


Math. random();


\> Math.random()


With the generated random numbers, we can generate operations like multiplications, the sum of the numbers, an integer between two values Etc...

Example :

Math.random() * 100


Math.round(x) :

Javascript Math. round() method returns the value of x rounded to its nearest integer. When it comes to the fractional part that number is greater than or equal to .5, the argument is rounded to the next highest integer. If the fractional part of the number is less than .5, the argument is rounded to the next lowest integer and we can also implement a random method in the round to get the round value of a random number, Initialise a value in var, By using Math. round() method round the input given is rounded, The next process is to round the valve we got in the random method.




var n = 12.7




Math.round(Math.random() \100)*


typeof (x) :

In javascript on a webpage, any input given by a user will always be a string, To find what type of input we give in the code we used a method called a typeof which returns what type of variables we used, In the given an example below we have taken n1 and n2 lets assign n1 as 10 and n2 as a string of ‘20’, By using the type of method we will get an Output of n1 as number and n2 as String, To convert a string to the number we use ParseInt (n2) after compilation the string is converted to a number.


var n1 = 10


var n2 = '20'


typeof n1


typeof n2


Math.PI :

The Math.PI is a property in JavaScript that is simply used to find the value of Pi in symbolic form Π which is nothing but it is the ratio of the circumference of a circle to its diameter, whose value is approximately 3.14.





Math.abs() :

Math. abs() method is mainly used to return the absolute value of a number. Math.abs() uses a number as its parameter and returns its absolute value.




values = Math.abs(67);

console.log(values); // 67

value = Math.abs(-7);

console.log(value); // 7

Math ceil() :

Math ceil() method increases the value of the given input number up to the closest integer value and returns the Output value.




console. log(Math. ceil(.97)); // Expected output: 1.


As we discussed the above-mentioned are some of the most important JavaScript Number Methods You Should Know in 2023.

Did you find this article valuable?

Support Skill Safari by becoming a sponsor. Any amount is appreciated!

Learn more about Hashnode Sponsors
Share this