Number primitive and object
Create a number and a primitive object
JavaScript
// Create an object and a primitive object with the value of PI
var n1 = new Number(Math.PI);
var n2 = Math.PI;
// Format the results
var result = n1 + " is " + typeof(n1) + "\n";
result += n2 + " is " + typeof(n2) + "\n";
// Show me value and type
alert(result);
// Fix to four decimal places
n1 = n1.toFixed(4);
n2 = n2.toFixed(4);
result = n1 + " is " + typeof(n1) + "\n";
result += n2 + " is " + typeof(n2) + "\n";
// Show me value and type
alert(result);