Changes

JavaScript Operators

857 bytes added, 18:33, 20 April 2007
no edit summary
Remembering that JavaScript will evaluate the expression in the inner parenthesese first we see that it will calculate the value of (6 + 1) before the rest of the expression is evaluated. This will be calculated to be 7 and stored. The rest of the expression will then be evaluated, and then the value 7 will be convered to a string (because it appears to the right of the "my lucky number" value) to create a string that reads "15 is my lucky number. So is 7".
 
== Logical Operators ==
 
''Logical Operators'' are also known as ''Boolean Operators'' because they evaluate parts of an expression and return a ''true'' or ''false'' value.
 
Perhaps the best way to understand how logical operators work is to construct a sentence rather than to look at a script example right away. Let's assume we want to check some aspect of two variables named x and y. Our sentence might read:
 
''If x is less than 10 AND y is greater than 20 display a message.''
 
Here the logical operator is the "AND" part of the sentence. If we were to express this in JavaScript we would use the comparision operators we covered earlier together with the && logical operator:
 
<pre>
 
if ((x < 10) && (y > 20)
document.write ("Message");
 
</pre>
 
Similarly if our sentence read:
 
''If x is less than 10 OR y is greater than 20 display a message.''
== Operator Precedence ==