23.04.2013 Views

javascript

javascript

javascript

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.

Figure 1–3. Doing some math with numbers<br />

■ Note JavaScript’s value type conversion feature is covered more fully in Chapter 2.<br />

Creating a Boolean Literal<br />

CHAPTER 1 ■ REPRESENTING DATA WITH VALUES<br />

Sometimes you will want a simple yes or no answer from JavaScript. In those circumstances, the return<br />

value for an expression will be true for yes and false for no.<br />

Click Clear in both Firebug panels, and let’s ask JavaScript whether Chocolate Fudge Brownie is just<br />

chocolate ice cream. Note that the === operator tells you whether two values are identical:<br />

"Chocolate Fudge Brownie" === "chocolate icecream";<br />

// false<br />

That’s an understatement. Alright, now let’s compare the previous calculation to its return value,<br />

before verifying our work with Figure 1–4:<br />

Math.round((6 * 14 + 21) / 7 * 365 * 100 / (4 * 260)) + " pints of Chocolate Fudge Brownie"<br />

===<br />

"526 pints of Chocolate Fudge Brownie";<br />

// true<br />

Figure 1–4. The === operator always returns a boolean.<br />

5

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

Saved successfully!

Ooh no, something went wrong!