ES6 | Number

The ES6 Number contains so many properties and methods to perform some numeric functions, that contains the date, integers, and floating points, etc. The ES6 is an object that can be called without creating it. With the help of ES6 Number in JavaScript, you can work with number objects so easily because the browsers convert number literals to instances of the number class automatically. There are so many properties and functions are available in ES6 Number. Also in the function section, there are lots of functions mentioned below. Below syntax will create number object.

Syntax:

var geeks = new Number(number); 

ES6 Number methods type:



  • Number Methods
  • Number Instances Methods

ES6 Number properties list with there brief description:

Property Description
Number.EPSILON This property defines the smallest intervals between two numbers.
Number.MAX_SAFE_INTEGER This property defines maximum safe integer in JavaScript(2^ 53 – 1).
Number.MAX_VALUE This property defines constants for the largest possible positive numbers( 1.7976931348623157 x 10308).
Number.MIN_SAFE_INTEGER This property defines the minimum safe integer constant(9007199254740991)
Number.MIN_VALUE This property defines constants for the smallest possible positive numbers(5 x 10-324)
Number.NaN This property defines Not-a-Number or unequal number.
Number.NEGATIVE_INFINITY This property defines a value less than defined number.
Number.POSITIVE_INFINITY This property defines a value greater than defined number.
Number.prototype This property defines special value representing infinity.

ES6 Number Methods: There are many functions mentioned below:

Function Description
Number.isNaN() Function This function returns whether the passed value is NaN or not.
Number.isFinite() Function This function returns whether the passed value is a finite number.
Number.isInteger() Function This function returns whether the passed value is an integer.
Number.isSafeInteger() Function This function determines whether the passed value is a safe integer(-252 to 252).
Number.parseFloat() Function This function is equivalent to parseFloat() of the global object.
Number.parseInt() Function This function is equivalent to parseInt() of the global object.

ES6 Number Instances Methods:

Function Description
toExponential() Function This function returns string representing the number in exponential notation.
toFixed() Function This function returns string representing the number in fixed-point notation.
toLocaleString() Function This function returns string with a language sensitive representation of this number.
toPrecision() Function This function returns string representing the number to a specified precision in fixed-point or exponential notation.
toString() Function This function returns string representing the specified object in the specified radix.
valueOf() Function This function returns primitive value of the specified object.

In the ES6 Number there are three important representing Literals those are:

  • Binary Literals
  • Octal Literals
  • Hexadecimal Literals

Binary Literals: You can represent binary literals with the 0b prefix it can be used as uppercase or lowercase does not matter.

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
   console.log(0b001) 
   console.log(0b010) 
</script>

chevron_right


Output:

1
2

Octal Literals: You can represent octal literals with the 0o prefix it can be used as uppercase or lowercase does not matter.

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
   console.log(0o010) 
   console.log(0o001)
</script>

chevron_right


Output:

8
1

Hexadecimal Literals: You can represent hexadecimal literals with the 0x prefix it can be used as uppercase or lowercase does not matter.

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
   console.log(0x010) 
   console.log(0x100) 
</script>

chevron_right


Output:

16
256

Note: The Edge and the Safari is the first two browsers that support all the ES6 features.
Supported Browsers: The browsers supported by ES6 Number are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Safari
  • Opera


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.