JavaScript Tutorial/Number Data Type/valueOf
Demonstrating the valueOf() method
<html>
<head>
<title>Demonstrating the valueOf() method</title>
<script type="text/javascript" language="javascript">
<!-- //
function DisplayValue(){
var entry1 ;
entry1 = prompt("Enter a floating point number", "123.123");
var number = new Number();
number = Number(entry1);
if (isNaN(number)){
document.write("<P>You did not enter a valid number.<br />");
}
else{
document.write(number.valueOf() + "</p>");
}
}
// -->
</script>
</head>
<body onload="DisplayValue()">
<P>This listing demonstrates the use of the valueOf() method.</p><br />
</body>
</html>
Number.valueOf()
The valueOf method gets the primitive value of a Number object as a number data type.
<html>
<body>
<script language="JavaScript1.1">
<!--
myNum = new Number(24)
document.write("The value of myNum is: " + myNum.valueOf());
-->
</script>
</body>
</html>