w3resource

Javascript Number Objects - Properties and Methods

Description

A number object holds primitive numeric values.

Can be created by number constructor, for example, new Number(value) or Number (value), where "value" is the numeric value of the Number object to be created, or value to be converted to a number.

Javascript Number Objects Property

Name Description Version
constructor Specifies the function that creates an object's prototype. Implemented in JavaScript 1.1
MAX_VALUE Returns the maximum numeric value represented in JavaScript. Implemented in JavaScript 1.1
MIN_VALUE Returns the number closest to 0, not the negative number represented in JavaScript. Implemented in JavaScript 1.1
NaN Represents a value that is not a number Implemented in JavaScript 1.1
NEGATIVE_INFINITY A special numeric value represents negative infinity. Implemented in JavaScript 1.1
POSITIVE_INFINITY A special numeric value represents positive infinity. Implemented in JavaScript 1.1
prototype Allows the add of properties to a Number object. Implemented in JavaScript 1.1

Javascript Number Objects Methods

Name Description Version
toSource Use to get a string representation (source code) of the number object. Implemented in JavaScript 1.3
toString Use to get a string representation of the specified number object. Implemented in JavaScript 1.1
valueOf Returns the primitive value of a number object as a number data type. Implemented in JavaScript 1.1

See also:

JavaScript Core objects, methods, properties.

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter

JavaScript: Tips of the Day

instance

class Calc {
	constructor() {
		this.count = 0 
	}

	increase() {
		this.count ++
	}
}

const calc = new Calc()
new Calc().increase()

console.log(calc.count)

We set the variable calc equal to a new instance of the Calc class. Then, we instantiate a new instance of Calc, and invoke the increase method on this instance. Since the count property is within the constructor of the Calc class, the count property is not shared on the prototype of Calc. This means that the value of count has not been updated for the instance calc points to, count is still 0.

Ref: https://bit.ly/2Hcpkm6