please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 3
Variables and Data Types
Next
 

3.4 boolean Values

The number and string data types have an infinite number of possible values. The boolean data type, on the other hand, has only two. As we saw in Chapter 2, Lexical Structure, the two legal boolean values are the keywords true and false. A boolean value represents a "truth value"--it says whether something is true or not.

boolean values are generally the result of comparisons we make in our JavaScript programs. For example, when we write:

a ==index.html 4
we are testing to see if the value of the variable a is equal to the number 4. If it is, then the result of this comparison is the boolean value true. If a is not equal to 4, then the result of the comparison is false. If boolean values are usually generated by comparisons, they are generally used in JavaScript control structures. For example, the if/else statement in JavaScript will perform one action if a boolean value is true and another action if the value is false. Generally, we will combine a comparison that creates a boolean value directly with a statement that uses it. The result looks like this:

if (a ==index.html 4) 
  b = b + 1;
else
  a = a + 1;
This code checks if a equals 4. If so, it adds 1 to b; otherwise, it adds 1 to a.

Instead of thinking of the two possible boolean values as true and false, it is sometimes convenient to think of them as "on" (true) and "off" (false) or "yes" (true) and "no" (false). Sometimes it is even useful to consider them equivalent to 1 (true) and 0 (false). (In fact, JavaScript does just this and converts true and false to 1 and 0 when necessary.)

C and C++ programmers should note that JavaScript has a distinct boolean data type, unlike C and C++ which simply use integer values to simulate boolean values. Java programmers should note that although JavaScript has a boolean type, it is not nearly as "pure" as the Java boolean data type--JavaScript boolean values are easily converted to and from other data types, and so in practice, the use of boolean values is much more like their use in C and C++ than in Java.


Previous Home Next
Strings Book Index Functions

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell

file: /Techref/language/java/script/definitive/ch03_04.htm, 6KB, , updated: 2019/10/14 15:00, local time: 2024/11/20 02:28,
TOP NEW HELP FIND: 
3.144.111.174:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://massmind.org/techref/language/java/script/definitive/ch03_04.htm"> [Chapter 3] 3.4 boolean Values</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .