JavaScript Numbers

The Numbers object in JavaScript represents a numerical value i.e., integer or floating-point number.

Let us see how we assign an integer value to a variable:

Let us see how we assign a floating-point value to a variable:

We can also create a Number object using Number():

JavaScript Number Properties

The following are the Number properties:

  • MAX_VALUE
  • MIN_VALUE

MAX_VALUE

The maximum value of a number in JavaScript. The value is 1.7976931348623157E+308. Let us see an example:

Output

JavaScript MAX_VALUE

MIN_VALUE

The minimum value of a number in JavaScript. The value is 5E-324. Let us see an example:

Output

JavaScript MIN_VALUE

JavaScript Number Methods

The following are the Number methods:

  • toString()
  • valueOf()
  • isFinite()
  • isInteger()
  • parseFloat()
  • parseInt()

JavaScript toString() method

The toString() method is used to return the string representation of a number. Let us see an example:

Output

JavaScript toString() method

JavaScript valueOf() method

The valueOf() method is used to return the number’s value. Let us see an example:

Output

JavaScript valueOf() method

JavaScript isFinite() method

The isFinite() method is used to check whether the value is a finite number. Let us see an example:

Output

JavaScript isFinite() method

JavaScript isInteger() method

The isInteger() method is used to check whether the value is an integer. Let us see an example:

Output

JavaScript isInteger() method

JavaScript parseFloat() method

The parseFloat() method is used to parse a string and convert it to a floating-point number. Let us see an example:

Output

JavaScript parseFloat() method

JavaScript parseInt() method

The parseInt() method is used to parse a string and convert it to a number. Let us see an example:

Output

JavaScript parseInt() method

JavaScript Objects
JavaScript Strings
Studyopedia Editorial Staff
contact@studyopedia.com

We work to create programming tutorials for all.

No Comments

Post A Comment

Discover more from Studyopedia

Subscribe now to keep reading and get access to the full archive.

Continue reading