Some notes on Number Function on JavaScript

A number is a mathematical object. It is used to count, measure, and label. Like every programming language, JavaScript also provides support for manipulating different types of numbers such as simple whole integers and floating point number.

Some Number methods and description:

isNaN() :

isNaN(123) //false
isNaN(-4.53) //false
isNaN(5-4)//false
isNaN(undefined) //true
isNaN('NaN') //true

parseFloat():

var a = parseFloat("20")
var b = parseFloat("20.33")
console.log(a);
// output: 20
console.log(b);
// output: 20.33

parseInt():

var a = parseInt("20")
var b = parseInt("20.33")
console.log(a);
// output: 20
console.log(b);
// output: 20

abs():

var a = Math.abs(-17.25);
var b = Math.abs(7.25);
console.log(a);
// output: 17.25
console.log(b);
// output: 7.25

ceil():

var a = Math.ceil(3.04);
var b = Math.ceil(3.9);
console.log(a);
// output: 4
console.log(b);
// output: 4

floor():

var a = Math.floor(7.9);
var b = Math.floor(7.1);
console.log(a);
// output: 7
console.log(b);
// output: 7

min():

var a = Math.min(50, -1, 10);
var b = Math.min(-5, -10, 10);
console.log(a);
// output: -1
console.log(b);
// output: -10

max():

var a = Math.max(50, -1, 10);
var b = Math.max(-5, -10, 10);
console.log(a);
// output: 50
console.log(b);
// output: 10

random():

var a = Math.random();console.log(a);
// any random value such as 0.2465502850108432

round():

var a = Math.round(2.3);
var b = Math.round(2.9);
console.log(a);
// output: 2
console.log(b);
// output: 3

sqrt():

var a = Math.sqrt(9);
var b = Math.sqrt(90);
console.log(a);
// output: 3
console.log(b);
// output: 9.486832980505138

These methods are often used by the JavaScript developers in almost every day. For all these features, JavaScript is becoming more popular day by day.

Mechatronics Engineer | Front-End Web Developer