X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript Number prototype Property

JavaScript Number Reference JavaScript Number Reference

Example

Create a new number method that returns a number's half value:

Number.prototype.myMethod = function() {
    return this.valueOf() / 2;
}

Use the new method on a number:

var n = 55;
var x = n.myMethod();

The result of x will be:

27.5

Try it yourself »


Definition and Usage

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.

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

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


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The prototype property is supported in all major browsers.


Syntax

Number.prototype.name = value


JavaScript Number Reference JavaScript Number Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook