How To Use Number Prototype Property In JavaScript

In this article I am going to explain about Number Prototype Property In JavaScript.
  • 1802

Use Number prototype Property in JavaScript

Number prototype property create a method for a number object property,

That method return the number's half value.

All browsers support number prototype property.

Syntax

object.prototype.name=value

Example

<!DOCTYPE html>

<html>

<body style ="background-color:Red">

 

<p id="demo">call the new myMet() method,

 and display the number 99 half value,

using the new myProp property.</p>

 

<button onclick="myFunction()">Click here</button>

 

<script type="text/javascript">

    Number.prototype.myMet = function ()

    {

        this.myProp = this.valueOf() / 2;

    }

 

    function myFunction()

     {

        var d = new Number(99);

        d.myMet();

        var x = document.getElementById("demo");

        x.innerHTML = d.myProp;

    }

</script>

 

</body>

</html>

Output1

op1.jpg

Output2

op2.jpg

Further Readings

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.