constructor

Returns the constructor function for an object.

The return value is a reference to the function, not the name of the function:

=> For JavaScript numbers --> returns function Number() { [native code] }

=> For JavaScript strings --> returns function String() { [native code] }

=> For JavaScript booleans --> returns function Boolean() { [native code] }

Example


number = 1;
console.log(number.constructor);

//[Function: Number] 
//in console.log you don't get { [native code] } part

MAX_VALUE

Returns the largest number possible in JavaScript.

This static property has a value of 1.7976931348623157e+308.

enlightened Numbers larger than MAX_VALUE are represented as infinity.

Example


console.log(Number.MAX_VALUE);
// 1.7976931348623157e+308

MAX_VALUE is a static property of the JavaScript Number object. We can only use it as Number.MAX_VALUE.

Using x.MAX_VALUE, where x is a number or a Number object, will return undefined:


number = 1;
console.log(number.MAX_VALUE);

//undefined

MIN_VALUE

Returns the smallest positive number possible in JavaScript.

This static property has a value of 5e-324.

enlightened Numbers smaller than this are converted to 0.


console.log(Number.MIN_VALUE);

//5e-324

enlightened MIN_VALUE is the value closest to 0. The most negative number is the negative MAX_NUMBER.

MIN_VALUE is a static property of the JavaScript Number object. You can only use it as Number.MIN_VALUE.

Using x.MIN_VALUE, where x is a number or a Number object, will return undefined:


number = 1;
console.log(number.MIN_VALUE);

//undefined

NEGATIVE_INFINITY

The NEGATIVE_INFINITY property represents negative infinity, means something that is lower than any other number.

Example


console.log(Number.NEGATIVE_INFINITY)

//-Infinity

NEGATIVE_INFINITY is a static property of the JavaScript Number object.

You can only use it as Number.NEGATIVE_INFINITY.

Using x.NEGATIVE_INFINITY, where x is a number or a Number object, will return undefined:


number = 1;
console.log(number.NEGATIVE_INFINITY);

//undefined

NaN

The NaN property represents "Not-a-Number" value. This property indicates that a value is not a legal number.

The NaN property is the same as the Number.Nan property.

Checkout this related post: The Difference Between IsNaN() Method And IsNaN() Function In JavaScript

POSITIVE_INFINITY

The POSITIVE_INFINITY property represents positive infinity which is something that is higher than any other number.

Example


console.log(Number.POSITIVE_INFINITY)

//Infinity

POSITIVE_INFINITY a static property of the JavaScript Number object.

You can only use it as Number.POSITIVE_INFINITY.

Using x.POSITIVE_INFINITY, where x is a number or a Number object, will return undefined:


number = 1;
console.log(number.POSITIVE_INFINITY);

//undefined

prototype

The prototype constructor allows you to add new properties and methods to JavaScript numbers.

When constructing a property, ALL numbers will be given the property, and its value, as default.

When constructing a method, ALL numbers will have this method available.

Example


Number.prototype.methodTemp = function() {
  return this.valueOf() * 2;
};

function tempFunction() {
  var number = 1;
  document.getElementById("any").innerHTML = n.methodTemp();
}


//assuming we have HTML element with an id = any
//it will print 2

enlightened Number.prototype does not refer to a single number object, but to the Number() object itself.

enlightened Prototype is a global object constructor which is available for all JavaScript objects.

Number Properties Cannot be Used on Variables

Number properties belongs to the JavaScript's number object wrapper called Number.

These properties can only be accessed as Number.MAX_VALUE.

Using myNumber.MAX_VALUE, where myNumber is a variable, expression, or value, will return undefined:


var a = 1;
var b = a.MAX_VALUE;     

console.log(b);

//undefined

Source: https://www.w3schools.com/js/js_number_methods.asp

0 Comments

Leave a reply

Your email address will not be published. required fields are marked *