Javascript - Number Number Type

Introduction

Number type is the reference type for numeric values.

To create a Number object, use the Number constructor and pass in any number. Here's an example:

var numberObject = new Number(10);

Number type overrides valueOf(), toLocaleString(), and toString().

The valueOf() method returns the primitive numeric value represented by the object, whereas the other two methods return the number as a string.

The toString() method optionally accepts a single argument indicating the radix in which to represent the number:

var num = 10;
console.log(num.toString());       //"10"
console.log(num.toString(2));      //"1010"
console.log(num.toString(8));      //"12"
console.log(num.toString(10));     //"10"
console.log(num.toString(16));     //"a"

The Number type has several additional methods used to format numbers as strings.