In [[Introducing JavaScript Variables]] we looked at the '=' assignent operator. This is the most basic of assignment operators and serves to simply assign a value to a variable. For example y = 10 assigns the value of 10 to a variable called y.
<google>ADSDAQBOX_FLOW</google>
The '=' assignment operator does not make any changes to the value before it is assigned to the variable. A number of assignment operators are available, however, that perform arithmetic on the value before assigning it to the variable. These are essentially combined arithmetic and assignment operators. The most common operators of this type, and their "long hand" equivalents are shown below:
<table border="1" cellspacing="0">
== Arithmetic Operators ==
As one might expect, arithmetic operators perform mathematical calculations on values and variables. JavaScript arithmetic is comprised of expressions made up of an operator and values to the right and left of that operator (better known as ''operands''). For example in the ''expression'' z = x + y, the + is the ''arithmetic operator'', x and y are the ''operands'' and the = is the "''assignment operator"'':
The following example adds the first ''operand'' (2) to the second operand (5) and assigns the result (7) to the variable ''y''.
</pre>
Arithmetic operatations operations can also be performed on variables:
<pre>
</pre>
These operators can also be used to increment and decrement a value after an expression as has been performed. Suppose you have a variable ''x'' which has been assigned a value of 5. You want to add the value of x to a variable called y and then decrement x by 1. One way to do this is as follows:
<pre>
<th>Operator<th>Description<th>Example</th>
<tr>
<td>==<td>Equal operator - retuns returns ''true'' if both operands are equal.<td>x == 6 returns ''true'' if x is 6</td>
<tr>
<td>!=<td>Not-equal operator - returns ''true'' if operands are not equal.</td><td>x != 6 returns true if x is not 6</td>
In this example the output will read "Hello, John, how are you?"
It is also important to understand that concatenation can handle variable types other than strings. For example, when the concatentation concatenation operator is used and it encounters a number it will convert that number to a string and join it to the string. For example:
<pre>
</pre>
The above code will output the message "You are visitor number 10". Note, however, that when an expression contains only one type of operator (i.e . only the + operator - see the "Operator Precedence" 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>
Exception encountered, of type "Error"
[7b8f479c] /index.php/Special:MobileDiff/7277 Error from line 434 of /var/www/techotopia/includes/diff/DairikiDiff.php: Call to undefined function each()
Backtrace:
#0 /var/www/techotopia/includes/diff/DairikiDiff.php(544): DiffEngine->diag()
#1 /var/www/techotopia/includes/diff/DairikiDiff.php(344): DiffEngine->compareSeq()
#2 /var/www/techotopia/includes/diff/DairikiDiff.php(227): DiffEngine->diffLocal()
#3 /var/www/techotopia/includes/diff/DairikiDiff.php(721): DiffEngine->diff()
#4 /var/www/techotopia/includes/diff/DairikiDiff.php(859): Diff->__construct()
#5 /var/www/techotopia/includes/diff/DairikiDiff.php(980): MappedDiff->__construct()
#6 /var/www/techotopia/extensions/MobileFrontend/includes/diff/InlineDiffFormatter.php(99): WordLevelDiff->__construct()
#7 /var/www/techotopia/includes/diff/DiffFormatter.php(140): InlineDiffFormatter->changed()
#8 /var/www/techotopia/includes/diff/DiffFormatter.php(82): DiffFormatter->block()
#9 /var/www/techotopia/extensions/MobileFrontend/includes/diff/InlineDifferenceEngine.php(117): DiffFormatter->format()
#10 /var/www/techotopia/includes/diff/DifferenceEngine.php(797): InlineDifferenceEngine->generateTextDiffBody()
#11 /var/www/techotopia/includes/diff/DifferenceEngine.php(728): DifferenceEngine->generateContentDiffBody()
#12 /var/www/techotopia/extensions/MobileFrontend/includes/specials/SpecialMobileDiff.php(241): DifferenceEngine->getDiffBody()
#13 /var/www/techotopia/extensions/MobileFrontend/includes/specials/SpecialMobileDiff.php(135): SpecialMobileDiff->showDiff()
#14 /var/www/techotopia/extensions/MobileFrontend/includes/specials/MobileSpecialPage.php(53): SpecialMobileDiff->executeWhenAvailable()
#15 /var/www/techotopia/includes/specialpage/SpecialPage.php(384): MobileSpecialPage->execute()
#16 /var/www/techotopia/includes/specialpage/SpecialPageFactory.php(553): SpecialPage->run()
#17 /var/www/techotopia/includes/MediaWiki.php(281): SpecialPageFactory::executePath()
#18 /var/www/techotopia/includes/MediaWiki.php(714): MediaWiki->performRequest()
#19 /var/www/techotopia/includes/MediaWiki.php(508): MediaWiki->main()
#20 /var/www/techotopia/index.php(41): MediaWiki->run()
#21 {main}