23.04.2013 Views

javascript

javascript

javascript

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 3 ■ OPERATORS<br />

76<br />

}<br />

};<br />

pureMapleSyrup: [1 + 1/3, "tbs"],<br />

groundPecans: [2, "tsp"]<br />

What if we want to know whether there’s more pastry flour or shredded Granny Smiths in the<br />

dough? Neither === nor !== would be of any help. Instead, we’d compare those ingredients with the ><br />

greater than operator, which like === and !== returns a boolean verdict—true if its first operand is<br />

greater than its second operand, and false if not. Try comparing some members with the > operator,<br />

verifying your work with Figure 3–13:<br />

var cake = {<br />

dough: {<br />

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

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

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

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

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

egg: [2],<br />

yogurtCheese: [2/3, "cup"],<br />

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

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

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

},<br />

icing: {<br />

yogurtCheese: [2/3, "cup"],<br />

pureMapleSyrup: [1 + 1/3, "tbs"],<br />

groundPecans: [2, "tsp"]<br />

}<br />

};<br />

cake.dough.organicPastryFlour[0] > cake.dough.shreddedGrannySmith[0];<br />

// false<br />

cake.dough.choppedPecans[0] > cake.dough.pureMapleSyrup[0];<br />

// true<br />

cake.dough.freshlyGroundNutmeg[0] > cake.dough.saigonCinnamon[0];<br />

// false<br />

cake.icing.yogurtCheese[0] > cake.dough.yogurtCheese[0];<br />

// false

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

Saved successfully!

Ooh no, something went wrong!