15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

484<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

Example<br />

You can use the toLowerCase() and toUpperCase() methods on literal strings,<br />

as follows:<br />

var newString = “HTTP://www.Netscape.COM”.toLowerCase()<br />

// result = “http://www.netscape.com”<br />

The methods are also helpful in comparing strings when case is not important, as<br />

follows:<br />

if (guess.toUpperCase() == answer.toUpperCase()) {...}<br />

// comparing strings without case sensitivity<br />

string.toString()<br />

string.valueOf()<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓ ✓ ✓<br />

<strong>Examples</strong><br />

Use The Evaluator to test the valueOf() method. Enter the following statements<br />

into the top text box and examine the values that appear in the Results field:<br />

a = new String(“hello”)<br />

typeof a<br />

b = a.valueOf()<br />

typeof b<br />

Because all other <strong>JavaScript</strong> core objects also have the valueOf() method, you can<br />

build generic functions that receive a variety of object types as parameters, and the<br />

script can branch its code based on the type of value that is stored in the object.<br />

Number Object<br />

Number.MAX_VALUE<br />

Properties<br />

MAX_VALUE<br />

MIN_VALUE<br />

NEGATIVE_INFINITY<br />

POSITIVE_INFINITY<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓ ✓ ✓ ✓ ✓

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!