|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
You might find it helpful to think of the comparison operators as questions. When you write the following: (x >= 10) youre really saying, Is the value of variable x greater than or equal to 10? The return value answers the question, TRUE or FALSE.
Logical Operators Comparison operators compare quantity or content for numeric and string expressions. Sometimes, however, you need to test a logical value such as whether a comparison operator returns TRUE or FALSE. JavaScripts logical operators enable you to compare expressions that return logical values. The following are JavaScripts logical operators:
Note that the and and or operators dont evaluate the second operand if the first operand provides enough information for the operator to return a value. This process, called short-circuit evaluation, can be significant when the second operand is a function call. For example: keepGoing = (userCancelled == FALSE) && (theForm.Submit()) If userCancelled is TRUE, the second operand, which submits the active form, is not called. String Operators You can use a few of the operators previously listed for string manipulation as well. All the comparison operators can be used on strings, too; the results depend on standard lexicographic ordering (ordering by the ASCII values of the string characters), but comparisons arent case sensitive. Additionally, you can use the + operator to concatenate strings, returning a string made up of the original strings joined together. The expression str = Hello, + World!; would assign the resulting string Hello, World! to the variable str. Controlling Your JavaScriptsSome scripts you write will be simple. They will execute the same way every time, one time per page. If you add a JavaScript to play a sound when users visit your home page, for example, it doesnt need to evaluate any conditions or do anything more than one time. More sophisticated scripts might require that you take different actions under different circumstances. You might also want to repeat the execution of a block of codeperhaps by a set number of times or as long as some condition is TRUE. JavaScript provides constructs for controlling the execution flow of your script based on conditions, as well as for repeating a sequence of operations.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |