This demonstrate Number datatype in JavaScript world. Number is Primitive and Object data type in JavaScript.
- Number representations in JavaScript, 2.Number as function and its properties,
A Pen by Praveen Dewangan on CodePen.
<h2>Number DataType Characteristice</h2> | |
<h3>Number Properties</h3> | |
<p id="number_properties"></p> | |
<table width="80%" border="1"> | |
<thead> | |
<th>Primitive Number</th> | |
<th>Object Number</th> | |
</thead> | |
<tr> | |
<td><p id="resultNumber"></p></td> | |
<td><p id="resultNumberObj"></p></td> | |
</tr> | |
</table> | |
<!-- | |
Reference : | |
1. http://www.tutorialsteacher.com/javascript/javascript-number | |
--> |
This demonstrate Number datatype in JavaScript world. Number is Primitive and Object data type in JavaScript.
A Pen by Praveen Dewangan on CodePen.
/* ----------- NUMBER Properties -----------*/ | |
document.getElementById('number_properties').innerHTML = | |
"Type of Number : <span class='danger'>"+typeof(Number) +"</span>"+ | |
"<br> Max Range : "+Number.MAX_VALUE + | |
" <br> Min Range : "+Number.MIN_VALUE+ | |
" <br> Positive Infinity : "+Number.POSITIVE_INFINITY+ | |
" <br> Negative Infiinity : "+Number.NEGATIVE_INFINITY+ | |
"<br> Not a number : "+Number.NaN; | |
/* ----------- INPUT MECHANISM -----------*/ | |
// var usrInNum = prompt("Enter Number",0); | |
var usrInNum = 1000; | |
var objNum = new Number(usrInNum); | |
var numNum = usrInNum; | |
/* ----------- Number Methods ----------- */ | |
document.getElementById('resultNumber').innerHTML = | |
"Original Value : "+numNum+" Type : "+typeof(numNum) | |
+"<br><span class='light'>{.valueOf( )}</span> Number Primitive Value : "+numNum.valueOf()+" Type : "+typeof(numNum.valueOf()) | |
+"<br> <span class='light'>{.toSring( )}</span>String Equivalent Value : "+numNum.toString()+" Type : "+typeof(numNum.toString()) | |
+"<br> <span class='light'>{.localeString( )}</span>Browser Locale String Value : "+numNum.toLocaleString()+" Type : "+typeof(numNum.toLocaleString()) | |
+"<br> <span class='light'>{.toPrecision( )}</span>Specified total digit : "+numNum.toPrecision(4)+" Type : "+typeof(numNum.toPrecision(4)) | |
+"<br> <span class='light'>{.toFixed( )}</span>Specified fraction digit : "+numNum.toFixed(4)+" Type : "+typeof(numNum.toFixed(4)) | |
+"<br><span class='light'>{.toExponential( )}</span>Exponential digit : "+numNum.toExponential(4)+" Type : "+typeof(numNum.toExponential(4)) | |
; | |
document.getElementById('resultNumberObj').innerHTML = | |
"Original Value : "+objNum+" Type : "+typeof(objNum) | |
+"<br> Object Value : "+objNum.valueOf()+" Type : "+typeof(objNum.valueOf()) | |
+"<br> String Equivalent Value : "+objNum.toString()+" Type : "+typeof(objNum.toString()) | |
+"<br> Browser Locale String Value : "+objNum.toLocaleString()+" Type : "+typeof(objNum.toLocaleString()) | |
+"<br> Specified total digit : "+objNum.toPrecision(4)+" Type : "+typeof(objNum.toPrecision(4)) | |
+"<br> Specified fraction digit : "+objNum.toFixed(4)+" Type : "+typeof(objNum.toFixed(4)) | |
+"<br>Exponential digit : "+objNum.toExponential(4)+" Type : "+typeof(objNum.toExponential(4)) | |
; |
.danger{ color:#D50000; } | |
.light{ | |
background: #689F38; | |
} |