JavaScript Operators - Comparison Operators
(Page 5 of 6 )
In the hopes of not getting sued, I am going to create a fictional fast food restaurant. Let's say this fast food "restaurant" serves Mexican food (though in truth you would never find these things on the menu in Mexico). We'll give it a neat little name: Burrito Bell. So now let's say you went to this Burrito Bell and bought a taco for about 20 cents. Then you go to grocery store and buy a taco kit and ground beef and make your own taco and stand them side by side.
The 20 cent taco looks nothing like your $3.00 homemade taco. Even the shells look different. The disturbing thing though is that when you look, smell, and taste the meat in the 20 cent taco you realize the creepy thing: that ain't hamburger beef. Hell, maybe it isn't beef period. I mean, what is that? Granted, you can't expect filet mignon in a 20 cent taco. But this stuff isn't even horse.
Now mind you, I still eat at this theoretical Burrito Bell. I'm just saying when you compare real meat to the Burrito Bell meat, something isn't matching up.
In JavaScript you can use Comparison Operators to compare values to one another. These are exceptionally handy when used in statements and loops (we will cover loops soon). But for now, let's work with a Boolean variable (boolean is a true/false, on/off, yes/no type of data).
<HTML>
<HEAD>
<script type="text/Javascript">
document.write(2 > 1)
</SCRIPT>
</HEAD>
</HTML>
The above would result in the following printing to your screen:
True.
What we have done is asked the computer to compare the values of 2 and 1. We stated that 2 was greater than 1 and asked the computer if this was true or false. The computer, being slightly smarter than you, told us it was True. Had we evaluated the statement 2 < 1, it would have returned a False response.
Next: Logical Captain? >>
More JavaScript Articles
More By James Payne