please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

Number Object

Name

Number Object---place-holder for numeric constants

Availability

Navigator 3.0

Synopsis

Number.constant

Constructor

new Number(value)

Arguments

value

The numeric value of the Number object being created. This argument will be converted to a number, if necessary.

Returns

The newly constructed Number object

Constants

MAX_VALUE

The largest representable number.

MIN_VALUE

The smallest representable number.

NaN

Special Not-a-Number value.

NEGATIVE_INFINITY

Special negative infinite value; returned on overflow.

POSITIVE_INFINITY

Special infinite value; returned on overflow.

Methods

toString()

Convert a number to a string, using a specified radix (base).

valueOf()

Return the primitive numeric value contained by the Number object.

Description

Numbers are a basic, primitive data type in JavaScript. In Navigator 3.0, however, JavaScript also supports the Number object, an object type that represents a primitive numeric value. JavaScript automatically converts between the primitive and object forms as necessary. In Navigator 3.0, you can explicitly create a Number object with the Number() constructor, although there is rarely any need to do so.

The Number() constructor is actually more commonly used as a place-holder for five useful numeric constants: the largest and smallest representable numbers, positive and negative infinity, and the special Not-a-Number value. Note that these values are properties of the Number() constructor function itself, not of individual number objects. For example, you use the MAX_VALUE property as follows:

biggest =index.html Number.MAX_VALUE
not like this:

n =index.html new Number(2);
biggest = n.MAX_VALUE

By contrast, the toString() method of the Number object is a method of each Number object, not of the Number() constructor function. As noted above, JavaScript automatically converts from primitive numeric values to Number objects whenever necessary. This means that we can use the toString() method with a variable that holds a number, even though that value is not actually an object:

value =index.html 1234;
binary_value = n.toString(2);

What happens in this code is that JavaScript implicitly invokes the Number() constructor to convert the number n to a temporary Number object for which the toString() method can be invoked. It is this toString() method that is the main reason for the existence of the Number object in the first place.

See Also

"Math", "Object"


Previous Home Next
netscape Book Index Number.MAX_VALUE

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell

file: /Techref/language/java/script/definitive/refp_265.htm, 7KB, , updated: 2019/10/14 15:00, local time: 2024/12/1 21:51,
TOP NEW HELP FIND: 
18.118.146.180:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://techref.massmind.org/Techref/language/JAVA/SCRIPT/definitive/refp_265.htm"> [Chapter 21] Reference: Number</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to techref.massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .