34,333
edits
Changes
→String Operators
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".
== Conditional Operators ==
JavaScript uses something called a ''ternary operator'' to provide a shortcut way of making decision in a script. The syntax of the ternary operator is as follows:
[condition]?[true expression]:[false expression]
The way this works is that ''[condition]'' is replaced with an expression that will return either ''true'' or ''false''. If the result is ''true'' then the expression that replaces the ''[true expression]'' is evaluated. Conversely, if the result was false then the ''[false expression]'' is evaluated. Let's see this in action:
<pre>
var myResult = (x > y) ? x-- : x++;
</pre>
In the above example is x is greater than y then the value of x will be decreased by 1. if the x is less than y then the value of x will be increased by 1.
== Logical Operators ==