Changes

Jump to: navigation, search

JavaScript Operators

3 bytes removed, 13:30, 5 June 2007
String Operators
</pre>
will output the message "You are visitor number 10". Note, however, that when an expresion expression contains only one type of operator (i.e only the + operator - see the "Operator PrecendencePrecedence" below for handling expressions with mixed operators) JavaScript evaluates the expression from left to right. So, if it encounters numbers before it encounters a string it will assume that it has found an arithmetic + rather than a string concatenation +. For example:
<pre>
</pre>
The output from the above will read "15 is my lucky number. So is 61". JavaScript also evaluates expressions from the inner parenthesese parentheses to outer parentheses. If you need to perform a calculation after a string appears in an expression, therefore, all you need to do is put ( and ) around the arithemtic arithmetic expression so that it gets evaluated before the string concatenation:
<pre>
</pre>
Remembering that JavaScript will evaluate the expression in the inner parenthesese parentheses 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 covered 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 ==
5
edits

Navigation menu