Javascript succinctly

Page 65

console.log(floatingPoint); // Logs '2.132'. </script></body></html>

Notes A numeric value can be a hexadecimal value or octal value in JavaScript, but this is typically not done.

Number() parameters The Number() constructor function takes one parameter: the numeric value being created. In the following snippet, we create a number object for the value 456 called numberOne. Sample: sample51.html <!DOCTYPE html><html lang="en"><body><script> var numberOne = new Number(456); console.log(numberOne); // Logs '456{}'. </script></body></html>

Notes When used with the new keyword, instances from the Number() constructor produce a complex object. You should avoid creating number values using the Number() constructor (use literal/primitive numbers) due to the potential problems associated with the typeof operator. The typeof operator reports number objects as 'object' instead of the primitive label ('number') you might expect. The literal/primitive value is just more concise.

Number() properties The Number() object has the following properties: Properties (e.g., Number.prototype;)  MAX_VALUE  MIN_VALUE  NaN

65


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.