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.

CHAPTER 3 ■ OPERATORS<br />

90<br />

Figure 3–23. Chaining && and || expression to do a complex comparison<br />

To better illustrate the JavaScript’s lazy evaluation of || and &&, let’s replace the final comparison<br />

with an alert() call that would say “Don’t panic!” Now click Run in Firebug. Firebug does not open an<br />

alert dialog box because JavaScript never bothered to invoke alert().<br />

var muffin = {<br />

oatFlour: [1/3, "cup"],<br />

barleyFlour: [1/3, "cup"],<br />

pastryFlour: [1 + 1/3, "cup"],<br />

freshlyGroundNutmeg: [1/4, "tsp"],<br />

saigonCinnamon: [1/2, "tsp"],<br />

seaSalt: [1/4, "tsp"],<br />

soda: [1, "tsp"],<br />

tartar: [1, "tsp"],<br />

mapleBrownCow: [1 + 1/2, "cup"],<br />

boysenberries: [2, "cup"],<br />

choppedPecans: [1/3, "cup"]<br />

};<br />

muffin.mapleBrownCow[0] < muffin.boysenberries[0] &&<br />

muffin.oatFlour[0] === muffin.barleyFlour[0] ||<br />

muffin.freshlyGroundNutmeg[0] < muffin.saigonCinnamon[0] &&<br />

muffin.choppedPecans[0]

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

Saved successfully!

Ooh no, something went wrong!