CD-43Chapter 6 .Programming Fundamentals, Part I Arithmetic operators

CD-43Chapter 6 .Programming Fundamentals, Part I Arithmetic operators It may seem odd to talk about text strings in the context of arithmetic operators, but you have already seen the special case of the plus (+) operator when one or more of the operands is a string. The plus operator instructs JavaScript to concatenate (pronounced kon-KAT-en-eight), or join, two strings together precisely where you place the operator. The string concatenation operator doesn t know about words and spaces, so the programmer must make sure that any two strings to be joined have the proper word spacing as part of the strings even if that means adding a space: firstName = John lastName = Doe fullName = firstName + + lastName JavaScript uses the same plus operator for arithmetic addition. When both operands are numbers, JavaScript knows to treat the expression as an arithmetic addition rather than a string concatenation. The standard math operators for addition, subtraction, multiplication, and division (+, -, *, /) are built into JavaScript. Comparison operators Another category of operator helps you compare values in scripts whether two values are the same, for example. These kinds of comparisons return a value of the Boolean type true or false. Table 6-2 lists the comparison operators. The operator that tests whether two items are equal consists of a pair of equal signs to distinguish it from the single equal sign assignment operator. Table 6-2 JavaScript Comparison Operators Symbol Description == Equals != Does not equal > Is greater than >= Is greater than or equal to < Is less than <= Is less than or equal to Where comparison operators come into greatest play is in the construction of scripts that make decisions as they run. A cook does this in the kitchen all the time: If the sauce is too watery, add a bit of flour. You see comparison operators in action in the next chapter.
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Leave a Reply