Prev Demo
JavaScript
>
Number Prototype Property
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> </head> <body> <p>Click the below button create a new number method that returns a number's half value .</p> <input type="button" value="ClickHere!" onclick="HalfNumber()" /> <p id="myId"></p> <script> Number.prototype.myMethod = function () { return this.valueOf() / 2; } function HalfNumber() { var A = 36; document.getElementById("myId").innerHTML = A.myMethod(); } </script> <p>Here in this case the number is <span style="background-color:pink">var A = 36</span>.</p> </body> </html>
Note: We DO NOT save your trial code in our database.
Output