<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Simon Whatley &#187; operators</title>
	<atom:link href="http://www.simonwhatley.co.uk/tag/operators/feed" rel="self" type="application/rss+xml" />
	<link>http://www.simonwhatley.co.uk</link>
	<description>The opposite of every great idea is another great idea</description>
	<lastBuildDate>Wed, 02 Nov 2011 09:28:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using JavaScript String Operators in ColdFusion 8</title>
		<link>http://www.simonwhatley.co.uk/using-javascript-string-operators-in-coldfusion-8</link>
		<comments>http://www.simonwhatley.co.uk/using-javascript-string-operators-in-coldfusion-8#comments</comments>
		<pubDate>Fri, 29 Feb 2008 08:57:07 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[assignment]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[concatenate]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[operators]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=434</guid>
		<description><![CDATA[In addition to the <a href="/using-javascript-comparison-operators-in-coldfusion-8" title="Using JavaScript Comparison Operators in ColdFusion 8">comparison</a> operators, which can be used on string values, the concatenation operator (&#038;) concatenates two string values together, returning another string that is the union of the two operand strings. For example, "my " &#038; "string" returns the string "my string".]]></description>
			<content:encoded><![CDATA[<p>In addition to the <a href="/using-javascript-comparison-operators-in-coldfusion-8" title="Using JavaScript Comparison Operators in ColdFusion 8">comparison</a> operators, which can be used on string values, the concatenation operator (&#038;) concatenates two string values together, returning another string that is the union of the two operand strings. For example, &#8220;my &#8221; &#038; &#8220;string&#8221; returns the string &#8220;my string&#8221;.</p>
<p>The shorthand <a href="/using-javascript-assignment-operators-in-coldfusion-8" title="Using JavaScript Assignment Operators in ColdFusion 8">assignment</a> operator &#038;= can also be used to concatenate strings. For example, if the variable mystring has the value &#8220;alpha&#8221;, then the expression mystring &#038;= &#8220;bet&#8221; evaluates to &#8220;alphabet&#8221; and assigns this value to mystring. This expression can be used in all <acronym title="ColdFusion Markup Language">CFML</acronym> expressions.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;">mystring <span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;Alpha&quot;</span>;</span>
<span style="color: #000099;">mystring <span style="color: #0000ff">&amp;</span><span style="color: #0000ff;">=</span> <span style="color: #009900;">&quot;bet&quot;</span>;</span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #800000;">&lt;cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#variables#&quot;</span> <span style="color: #0000ff;">label</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Concatenating Strings&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>This returns the following output:</p>
<p><img src='http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/02/concatenating-string-operator.png' alt='Concatenating Strings Operator Example' /></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/using-javascript-string-operators-in-coldfusion-8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using JavaScript Comparison Operators in ColdFusion 8</title>
		<link>http://www.simonwhatley.co.uk/using-javascript-comparison-operators-in-coldfusion-8</link>
		<comments>http://www.simonwhatley.co.uk/using-javascript-comparison-operators-in-coldfusion-8#comments</comments>
		<pubDate>Thu, 28 Feb 2008 09:17:24 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[cfscript]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[comparison]]></category>
		<category><![CDATA[equal]]></category>
		<category><![CDATA[greater]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[less]]></category>
		<category><![CDATA[not]]></category>
		<category><![CDATA[operators]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=432</guid>
		<description><![CDATA[Following on from the first three parts of the "Using JavaScript Operators" in ColdFusion 8, where I introduced <a href="/using-javascript-arithmetic-operators-in-coldfusion-8" title="Using JavaScript Arithmetic Operators in ColdFusion 8">Arithmetic</a>, <a href="/using-javascript-assignment-operators-in-coldfusion-8" title="Using JavaScript Assignment Operators in ColdFusion 8">Assignment</a> and <a href="/using-javascript-logical-operators-in-coldfusion-8" title="Using JavaScript Logical Operators in ColdFusion 8">Logical</a> Operators, it is now the turn of Comparison Operators.]]></description>
			<content:encoded><![CDATA[<p>Following on from the first three parts of my &#8220;Using JavaScript Operators&#8221; in ColdFusion 8 series, where I introduced <a href="/using-javascript-arithmetic-operators-in-coldfusion-8" title="Using JavaScript Arithmetic Operators in ColdFusion 8">Arithmetic</a>, <a href="/using-javascript-assignment-operators-in-coldfusion-8" title="Using JavaScript Assignment Operators in ColdFusion 8">Assignment</a> and <a href="/using-javascript-logical-operators-in-coldfusion-8" title="Using JavaScript Logical Operators in ColdFusion 8">Logical</a> Operators, it is now the turn of Comparison Operators.</p>
<p>In the past we have been restricted to the more &#8216;wordy&#8217; operators such as those defined in the first table below.</p>
<table>
<tbody>
<tr>
<th>
Operator
    </th>
<th>
Description
    </th>
</tr>
<tr>
<td>
<code>IS</code><br />
<code>EQUAL</code><br />
<code>EQ</code>
    </td>
<td>
Perform a case-insensitive comparison of two values. Return True if the values are identical.
    </td>
</tr>
<tr>
<td>
<code>IS NOT</code><br />
<code>NOT EQUAL</code><br />
<code>NEQ</code>
    </td>
<td>
Opposite of IS. Perform a case-insensitive comparison of two values. Return True if the values are not identical.
    </td>
</tr>
<tr>
<td>
<code>CONTAINS</code>
    </td>
<td>
Return True if the value on the left contains the value on the right.
    </td>
</tr>
<tr>
<td>
<code>DOES NOT CONTAIN</code>
    </td>
<td>
Opposite of CONTAINS. Return True if the value on the left does not contain the value on the right.
    </td>
</tr>
<tr>
<td>
<code>GREATER THAN</code><br />
<code>GT</code>
    </td>
<td>
Return True if the value on the left is greater than the value on the right.
    </td>
</tr>
<tr>
<td>
<code>LESS THAN</code><br />
<code>LT</code>
    </td>
<td>
Opposite of GREATER THAN. Return True if the value on the left is smaller than the value on the right.
    </td>
</tr>
<tr>
<td>
<code>GREATER THAN OR EQUAL TO</code><br />
<code>GTE</code><br />
<code>GE</code>
    </td>
<td>
Return True if the value on the left is greater than or equal to the value on the right.
    </td>
</tr>
<tr>
<td>
<code>LESS THAN OR EQUAL TO</code><br />
<code>LTE</code><br />
<code>LE</code>
    </td>
<td>Return True if the value on the left is less than or equal to the value on the right.</td>
</tr>
</tbody>
</table>
<p>However, with the arrival of ColdFusion 8, the <acronym title="ColdFusion Markup Language">CFML</acronym> scripting language has been brought into line with other major scripting languages. This change is undoubtedly good for ColdFusion as developers familiar with the ActionScript and JavaScript syntax can now more effectively code ColdFusion and vice-versa.</p>
<p>The following table describes the comparison operators that can be used in ColdFusion 8, albeit used in <code>&lt;cfscript&gt;</code> expressions only:</p>
<table>
<tbody>
<tr>
<th>Operator</th>
<th>Description</th>
<th>Examples returning true<sup>1</sup></th>
</tr>
<tr>
<td>Equal (<code>==</code>)</td>
<td>If the two operands are not of the same type, JavaScript converts the operands then applies strict comparison. If either operand is a number or a boolean, the operands are converted to numbers; if either operand is a string, the other one is converted to a string</td>
<td>
<p>
<code>3 == var1</code><br />
<code>"3" == var1</code><br />
<code>3 == '3'</code>
</p>
</td>
</tr>
<tr>
<td>Not equal (<code>!=</code>)</td>
<td>Returns true if the operands are not equal. If the two operands are not of the same type, JavaScript attempts to convert the operands to an appropriate type for the comparison.</td>
<td>
<p><code>var1 != 4
var1 != "5"</code>
</p>
</td>
</tr>
<tr>
<td>Greater than (<code>&gt;</code>)</td>
<td>Returns true if the left operand is greater than the right operand.</td>
<td>
<p><code>var2 &gt; var1</code>
</p>
</td>
</tr>
<tr>
<td>Greater than or equal (<code>&gt;=</code>)</td>
<td>Returns true if the left operand is greater than or equal to the right operand.</td>
<td>
<p><code>var2 &gt;= var1
var1 &gt;= 3</code>
</p>
</td>
</tr>
<tr>
<td>Less than (<code>&lt;</code>)</td>
<td>Returns true if the left operand is less than the right operand.</td>
<td>
<p><code>var1 &lt; var2</code>
</p>
</td>
</tr>
<tr>
<td>Less than or equal to (<code>&lt;=</code>)</td>
<td>Returns true if the left operand is less than or equal to the right operand.</td>
<td>
<p>
<code>var1 &lt;= var2</code><br />
<code>var2 &lt;= 5</code>
</p>
</td>
</tr>
</tbody>
</table>
<p><small><sup>1</sup> These examples assume that <code>var1</code> has been assigned the value 3 and <code>var2</code> has been assigned the value 4.</small></p>
<p>Below are just a few simple examples of the new ColdFusion operators and their use:</p>
<p><strong>IS EQUAL TO</strong></p>
<p>In the below example, the value of <code>var1</code> is not equal to <code>var2</code>, therefore the comparison returns <code>false</code> and the <code>else</code> statement is processed, writing the number 4 to the screen.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;">var1 <span style="color: #0000ff">=</span> <span style="color: #ff0000;">3</span>;</span>
<span style="color: #000099;">var2 <span style="color: #0000ff">=</span> <span style="color: #ff0000;">4</span>;</span>
<span style="color: #000099;"><span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span>var1 <span style="color: #0000ff">=</span><span style="color: #0000ff">=</span> var2<span style="color: #000000;">&#41;</span> <span style="color: #808080;">//returns false</span></span>
<span style="color: #000099;">	<span style="color: #800080;">writeOutput</span><span style="color: #000000;">&#40;</span>var1<span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;"><span style="color: #0000ff;">else</span></span>
<span style="color: #000099;">	<span style="color: #800080;">writeOutput</span><span style="color: #000000;">&#40;</span>var2<span style="color: #000000;">&#41;</span>; <span style="color: #808080;">//writes out 4</span></span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span></pre></div></div>

<p><strong>IS NOT EQUAL TO</strong></p>
<p>In the below example, the variable <code>var1</code> is not equal to 4, therefore the statement returns <code>true</code>, writing 3 to the screen. The second <code>if</code> statement serves to emphasise that ColdFusion is not strictly typed. Therefore comparing <code>var1</code> to an <a href="http://en.wikipedia.org/wiki/Integer" title="Wikipedia Integer Definition" rel="nofollow">Integer</a> or a <a href="http://en.wikipedia.org/wiki/String_%28computer_science%29" title="Wikipedia String Definition" rel="nofollow">String</a> is possible. ColdFusion handles type conversion in the background.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;">var1 <span style="color: #0000ff">=</span> <span style="color: #ff0000;">3</span>;</span>
<span style="color: #000099;">var2 <span style="color: #0000ff">=</span> <span style="color: #ff0000;">4</span>;</span>
<span style="color: #000099;"><span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span>var1 !<span style="color: #0000ff">=</span> <span style="color: #ff0000;">4</span><span style="color: #000000;">&#41;</span> <span style="color: #808080;">//returns true</span></span>
<span style="color: #000099;">	<span style="color: #800080;">writeOutput</span><span style="color: #000000;">&#40;</span>var1<span style="color: #000000;">&#41;</span>; <span style="color: #808080;">//writes out 3</span></span>
&nbsp;
<span style="color: #000099;"><span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span>var1 !<span style="color: #0000ff">=</span> <span style="color: #009900;">&quot;5&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #808080;">//returns true</span></span>
<span style="color: #000099;">	<span style="color: #800080;">writeOutput</span><span style="color: #000000;">&#40;</span>var1<span style="color: #000000;">&#41;</span>; <span style="color: #808080;">//writes out 3</span></span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span></pre></div></div>

<p><strong>IS GREATER THAN</strong></p>
<p>In the below example, <code>var2</code> is greater than <code>var1</code>, therefore the value of <code>var2</code>, 4, is printed out on screen. Changing the operator to Greater Than or Equal To (<code>&gt;=</code>) would also return the same result. However, using the Less Than (<code>&lt;</code>) and Less Than or Equal To (<code>&lt;=</code>) operators would return false and not write a value to the screen.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;">var1 <span style="color: #0000ff">=</span> <span style="color: #ff0000;">3</span>;</span>
<span style="color: #000099;">var2 <span style="color: #0000ff">=</span> <span style="color: #ff0000;">4</span>;</span>
<span style="color: #000099;"><span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span>var2 <span style="color: #800000;">&gt;</span> var1<span style="color: #000000;">&#41;</span> <span style="color: #808080;">//returns true</span></span>
<span style="color: #000099;">	<span style="color: #800080;">writeOutput</span><span style="color: #000000;">&#40;</span>var2<span style="color: #000000;">&#41;</span>; <span style="color: #808080;">//writes out 4</span></span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span></pre></div></div>

<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/using-javascript-comparison-operators-in-coldfusion-8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using JavaScript Logical Operators in ColdFusion 8</title>
		<link>http://www.simonwhatley.co.uk/using-javascript-logical-operators-in-coldfusion-8</link>
		<comments>http://www.simonwhatley.co.uk/using-javascript-logical-operators-in-coldfusion-8#comments</comments>
		<pubDate>Wed, 27 Feb 2008 09:09:05 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[logical]]></category>
		<category><![CDATA[not]]></category>
		<category><![CDATA[operators]]></category>
		<category><![CDATA[or]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=433</guid>
		<description><![CDATA[Logical operators are typically used with Boolean (logical) values; when they are, they return a Boolean value. However, the &#038;& and &#124;&#124; operators actually return the value of one of the specified operands, so if these operators are used with non-Boolean values, they may return a non-Boolean value.]]></description>
			<content:encoded><![CDATA[<p>Following on from my posts on <a href="/using-javascript-arithmetic-operators-in-coldfusion-8" title="Using JavaScript Arithmetic Operators in ColdFusion 8">Arithmetic</a> and <a href="/using-javascript-assignment-operators-in-coldfusion-8" title="Using JavaScript Assignment Operators in ColdFusion 8">Assignment</a> operators, Logical operators are typically used with Boolean (logical) values; when they are, they return a Boolean value. However, the &#038;&#038; and || operators actually return the value of one of the specified operands, so if these operators are used with non-Boolean values, they may return a non-Boolean value.</p>
<p>The logical operators are described in the following table:</p>
<table>
<tbody>
<tr>
<th>Operator</th>
<th>Usage</th>
<th>Description</th>
</tr>
<tr>
<td>Logical AND (<code>&amp;&amp;</code>)</td>
<td><code>expr1 &amp;&amp; expr2</code></td>
<td>Returns <code>expr1</code> if it can be converted to false; otherwise, returns <code>expr2</code>. Thus, when used with Boolean values, <code>&amp;&amp;</code> returns true if both operands are true; otherwise, returns false.</td>
</tr>
<tr>
<td>Logical OR (<code>||</code>)</td>
<td><code>expr1 || expr2</code></td>
<td>Returns <code>expr1</code> if it can be converted to true; otherwise, returns <code>expr2</code>. Thus, when used with Boolean values, <code>||</code> returns true if either operand is true; if both are false, returns false.</td>
</tr>
<tr>
<td>Logical NOT (<code>!</code>)</td>
<td><code>!expr</code></td>
<td>Returns false if its single operand can be converted to true; otherwise, returns true.</td>
</tr>
</tbody>
</table>
<p>Using ColdFusion, the Logical operators can be expressed as follows:</p>
<p><strong>Logical AND</strong></p>
<p>In the below example, both operands, <code>x</code> and <code>y</code>, return true, therefore <code>myVariable</code> is set to <code>true</code> within the logical statement.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;"><span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">9</span>;</span>
<span style="color: #000099;"><span style="color: #0000ff">y</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">2</span>;</span>
<span style="color: #000099;">myVariab<span style="color: #0000ff;">le</span> <span style="color: #0000ff">=</span> false;</span>
&nbsp;
<span style="color: #000099;"><span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0000ff">x</span> <span style="color: #800000;">&lt;</span> <span style="color: #ff0000;">10</span> <span style="color: #0000ff;">&amp;&amp;</span> <span style="color: #0000ff">y</span> <span style="color: #800000;">&gt;</span> <span style="color: #ff0000;">1</span><span style="color: #000000;">&#41;</span></span>
<span style="color: #000099;"><span style="color: #000000;">&#123;</span></span>
<span style="color: #000099;">	myVariab<span style="color: #0000ff;">le</span> <span style="color: #0000ff">=</span> true;</span>
<span style="color: #000099;"><span style="color: #000000;">&#125;</span></span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span></pre></div></div>

<p><img src='http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/02/logical-and-operator.png' alt='Logical AND Operator Example Results' /></p>
<p><strong>Logical OR</strong></p>
<p>In the below example, neither <code>x</code> equals 10 nor <code>y</code> equals 1, therefore the first part of the logical statement is not resolved. Instead, the <code>else</code> statement is processed, assigning the boolean value <code>false</code> to the variable <code>myVariable</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;"><span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">9</span>;</span>
<span style="color: #000099;"><span style="color: #0000ff">y</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">2</span>;</span>
&nbsp;
<span style="color: #000099;"><span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span><span style="color: #0000ff">=</span> <span style="color: #ff0000;">10</span> || <span style="color: #0000ff">y</span> <span style="color: #0000ff">=</span><span style="color: #0000ff">=</span> <span style="color: #ff0000;">1</span><span style="color: #000000;">&#41;</span></span>
<span style="color: #000099;"><span style="color: #000000;">&#123;</span></span>
<span style="color: #000099;">	myVariab<span style="color: #0000ff;">le</span> <span style="color: #0000ff">=</span> true;</span>
<span style="color: #000099;"><span style="color: #000000;">&#125;</span></span>
<span style="color: #000099;"><span style="color: #0000ff;">else</span></span>
<span style="color: #000099;"><span style="color: #000000;">&#123;</span></span>
<span style="color: #000099;">	myVariab<span style="color: #0000ff;">le</span> <span style="color: #0000ff">=</span> false;</span>
<span style="color: #000099;"><span style="color: #000000;">&#125;</span></span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span></pre></div></div>

<p><img src='http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/02/logical-or-operator.png' alt='Logical OR Operator Example Results' /></p>
<p><strong>Logical NOT</strong></p>
<p>In the below example, <code>x</code> does not equal <code>y</code>. Ordinarily this would result in the logical statement being evaluated, however, a logical negation has been applied to the beginning of the expression to be evaluated, therefore the variable <code>myVariable</code> is assigned the boolean value <code>true</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;"><span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">9</span>;</span>
<span style="color: #000099;"><span style="color: #0000ff">y</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">2</span>;</span>
<span style="color: #000099;">myVariab<span style="color: #0000ff;">le</span> <span style="color: #0000ff">=</span> false;</span>
&nbsp;
<span style="color: #000099;"><span style="color: #0000ff;">if</span> <span style="color: #000000;">&#40;</span>!<span style="color: #0000ff">x</span><span style="color: #0000ff;">==</span><span style="color: #0000ff">y</span><span style="color: #000000;">&#41;</span></span>
<span style="color: #000099;"><span style="color: #000000;">&#123;</span></span>
<span style="color: #000099;">	myVariab<span style="color: #0000ff;">le</span> <span style="color: #0000ff">=</span> true;</span>
<span style="color: #000099;"><span style="color: #000000;">&#125;</span></span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span></pre></div></div>

<p><img src='http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/02/logical-not-operator.png' alt='Logical NOT Operator Example Results' /></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/using-javascript-logical-operators-in-coldfusion-8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using JavaScript Assignment Operators in ColdFusion 8</title>
		<link>http://www.simonwhatley.co.uk/using-javascript-assignment-operators-in-coldfusion-8</link>
		<comments>http://www.simonwhatley.co.uk/using-javascript-assignment-operators-in-coldfusion-8#comments</comments>
		<pubDate>Tue, 26 Feb 2008 10:15:53 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[assignment]]></category>
		<category><![CDATA[assignment operator]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[equal]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Meaning]]></category>
		<category><![CDATA[operators]]></category>
		<category><![CDATA[shorthand]]></category>
		<category><![CDATA[subtraction]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=431</guid>
		<description><![CDATA[In my first post in this series, I introduced <a href="/using-javascript-arithmetic-operators-in-coldfusion-8" title="Using JavaScript Arithmetic Operators in ColdFusion 8">Using JavaScript Arithmetic Operators in ColdFusion 8</a>. Now we'll concentrate on Assignment operators.

An assignment operator assigns a value to its left operand based on the value of its right operand.

The basic assignment operator is equal (=), which assigns the value of its right operand to its left operand. That is, x = y assigns the value of y to x. The other assignment operators are usually shorthand for standard operations, as shown in the following table.]]></description>
			<content:encoded><![CDATA[<p>In my first post in this series, I introduced <a href="/using-javascript-arithmetic-operators-in-coldfusion-8" title="Using JavaScript Arithmetic Operators in ColdFusion 8">Using JavaScript Arithmetic Operators in ColdFusion 8</a>. Now we&#8217;ll concentrate on Assignment operators.</p>
<p>An assignment operator assigns a value to its left operand based on the value of its right operand.</p>
<p>The basic assignment operator is equal (=), which assigns the value of its right operand to its left operand. That is, x = y assigns the value of y to x. The other assignment operators are usually shorthand for standard operations, as shown in the following table.</p>
<table>
<tbody>
<tr>
<th>Operator</th>
<th>Shorthand operator</th>
<th>Meaning</th>
</tr>
<tr>
<td>+=</td>
<td><code>x += y</code></td>
<td><code>x = x + y</code></td>
</tr>
<tr>
<td>-=</td>
<td><code>x -= y</code></td>
<td><code>x = x - y</code></td>
</tr>
<tr>
<td>*=</td>
<td><code>x *= y</code></td>
<td><code>x = x * y</code></td>
</tr>
<tr>
<td>/=</td>
<td><code>x /= y</code></td>
<td><code>x = x / y</code></td>
</tr>
<tr>
<td>%=</td>
<td><code>x %= y</code></td>
<td><code>x = x % y</code></td>
</tr>
</tbody>
</table>
<p>In unusual situations, the assignment operator is not identical to the Meaning expression in the above table. When the left operand of an assignment operator itself contains an assignment operator, the left operand is evaluated only once. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;">a<span style="color: #000000;">&#91;</span>i<span style="color: #0000ff;">++</span><span style="color: #000000;">&#93;</span> <span style="color: #0000ff;">+</span><span style="color: #0000ff">=</span> <span style="color: #ff0000;">5</span> <span style="color: #808080;">//i is evaluated only once</span></span>
<span style="color: #000099;">a<span style="color: #000000;">&#91;</span>i<span style="color: #0000ff;">++</span><span style="color: #000000;">&#93;</span> <span style="color: #0000ff">=</span> a<span style="color: #000000;">&#91;</span>i<span style="color: #0000ff;">++</span><span style="color: #000000;">&#93;</span> <span style="color: #0000ff;">+</span> <span style="color: #ff0000;">5</span> <span style="color: #808080;">//i is evaluated twice</span></span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span></pre></div></div>

<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/using-javascript-assignment-operators-in-coldfusion-8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using JavaScript Arithmetic Operators in ColdFusion 8</title>
		<link>http://www.simonwhatley.co.uk/using-javascript-arithmetic-operators-in-coldfusion-8</link>
		<comments>http://www.simonwhatley.co.uk/using-javascript-arithmetic-operators-in-coldfusion-8#comments</comments>
		<pubDate>Mon, 25 Feb 2008 09:04:54 +0000</pubDate>
		<dc:creator>Simon</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[addition]]></category>
		<category><![CDATA[arithmetic]]></category>
		<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[decrement]]></category>
		<category><![CDATA[division]]></category>
		<category><![CDATA[examples]]></category>
		<category><![CDATA[increment]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[literals]]></category>
		<category><![CDATA[modulus]]></category>
		<category><![CDATA[multiplication]]></category>
		<category><![CDATA[operators]]></category>
		<category><![CDATA[subtraction]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[variables]]></category>

		<guid isPermaLink="false">http://www.simonwhatley.co.uk/?p=430</guid>
		<description><![CDATA[An often mentioned complaint by ColdFusion developers is the lack of operators commonly found in other programming languages such as JavaScript. For example, instead of the greater-than (<code>></code>) symbol we have been restricted to the more wordy <code>GT</code> or <code>GREATER THAN</code> operator. However, in ColdFusion 8 this has changed and we have more freedom to use familiar JavaScript operators in <code><cfscript></code> blocks.

In the following series of posts, I will introduce the changes and show some simple examples. The first in the series is Arithmetic Operators.

Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value. The standard arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/).

These operators work as they do in most other programming languages.]]></description>
			<content:encoded><![CDATA[<p>An often mentioned complaint by ColdFusion developers is the lack of operators commonly found in other programming languages such as JavaScript. For example, instead of the greater-than (<code>&gt;</code>) symbol we have been restricted to the more wordy <code>GT</code> or <code>GREATER THAN</code> operator. However, in ColdFusion 8 this has changed and we have more freedom to use familiar JavaScript operators in <code>&lt;cfscript&gt;</code> blocks.</p>
<p>In the following series of posts, I will introduce the changes and show some simple examples. The first in the series is Arithmetic Operators.</p>
<p>Arithmetic operators take numerical values (either literals or variables) as their operands and return a single numerical value. The standard arithmetic operators are addition (+), subtraction (-), multiplication (*), and division (/). These haven&#8217;t changed from ColdFusion version 7 to 8.</p>
<p>A key change comes with the use of <a href="http://en.wikipedia.org/wiki/Unary_operator" title="Unary Operators" rel="nofollow">Unary Operators</a>. The unary operators require only one operand; they perform various operations such as incrementing/decrementing a value by one, negating an expression, or inverting the value of a boolean.</p>
<p>These operators work as they do in most other programming languages.</p>
<p><strong>% (Modulus)</strong></p>
<p>The modulus operator is used as follows:</p>
<p><code>var1 % var2</code></p>
<p>The modulus operator returns the first operand modulo the second operand, that is, var1 modulo var2, in the preceding statement, where var1 and var2 are variables. The modulo function is the integer remainder of dividing var1 by var2. For example, 12 % 5 returns 2.</p>
<p>In ColdFusion this is written:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfif</span> myQuery.currentRow % <span style="color: #ff0000;">2</span><span style="color: #0000ff;">&gt;&lt;/</span>cfif<span style="color: #0000ff;">&gt;</span></span></pre></div></div>

<p>A good use of the modulus operator would be to alternate row colours in tabular data. The above code could be wrapped around a <acronym title="Cascading Style Sheet">CSS</acronym> class, dynamically changing the name of the class on each row iteration.</p>
<p><strong>++ (Increment)</strong></p>
<p>The increment operator is used as follows:</p>
<p><code>var++ or ++var</code></p>
<p>This operator increments (adds one to) its operand and returns a value. If used postfix, with operator after operand (for example, x++), then it returns the value before incrementing. If used prefix with operator before operand (for example, ++x), then it returns the value after incrementing.</p>
<p>For example, if x is 10, then the statement y = x++ sets y to 10 and increments x to 11. If x is 10, then the statement y = ++x increments x to 11 and sets y to 11.</p>
<p>In ColdFusion, a simple example:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">10</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">y</span> <span style="color: #0000ff">=</span> <span style="color: #0000ff">x</span><span style="color: #0000ff;">++</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #800000;">&lt;cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#variables#&quot;</span> <span style="color: #0000ff;">label</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Increment Operator Test 1&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>The above code returns:</p>
<p><img src='http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/02/increment-operator-test-1.png' alt='Increment Operator Test 1' /></p>
<p>Switching the order of the operator to be before the variable:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">10</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">y</span> <span style="color: #0000ff">=</span> <span style="color: #0000ff;">++</span><span style="color: #0000ff">x</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #800000;">&lt;cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#variables#&quot;</span> <span style="color: #0000ff;">label</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Increment Operator Test 2&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>The above code returns; note that both variables return 11:</p>
<p><img src='http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/02/increment-operator-test-2.png' alt='Increment Operator Test 2' /></p>
<p><strong><code>--</code> (Decrement)</strong></p>
<p>The decrement operator is used as follows:</p>
<p><code>var-- or --var</code></p>
<p>This operator decrements (subtracts one from) its operand and returns a value. If used postfix (for example, x&#8211;), then it returns the value before decrementing. If used prefix (for example, &#8211;x), then it returns the value after decrementing.</p>
<p>For example, if x is three, then the statement y = x&#8211; sets y to 3 and decrements x to 2. If x is 3, then the statement y = &#8211;x decrements x to 2 and sets y to 2.</p>
<p>In ColdFusion, a slightly more complex example:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;"><span style="color: #808080;">//decrement the variable y</span></span>
<span style="color: #000099;"><span style="color: #0000ff;">for</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff">y</span><span style="color: #0000ff;">=</span><span style="color: #ff0000;">5</span>; <span style="color: #0000ff">y</span> <span style="color: #800000;">&gt;</span> <span style="color: #ff0000;">0</span>; y<span style="color: #0000ff;">--</span><span style="color: #000000;">&#41;</span></span>
<span style="color: #000099;"><span style="color: #000000;">&#123;</span></span>
<span style="color: #000099;">	<span style="color: #800080;">writeOutput</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff">y</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;"><span style="color: #000000;">&#125;</span></span>
<span style="color: #000099;"><span style="color: #808080;">//returns 54321</span></span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span></pre></div></div>

<p>The above code loops from 5 to 1, decrementing the value of <code>y</code> by 1 on each iteration. The returned output is therefore 54321.</p>
<p>We could now combine the increment and decrement operators to do even more complex operations. E.g.:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #000099;"><span style="color: #800000;">&lt;cfscript&gt;</span></span>
<span style="color: #000099;"><span style="color: #808080;">//create a new array</span></span>
<span style="color: #000099;">arrTemp <span style="color: #0000ff">=</span> <span style="color: #800080;">arrayNew</span><span style="color: #000000;">&#40;</span><span style="color: #ff0000;">1</span><span style="color: #000000;">&#41;</span>;</span>
<span style="color: #000099;"><span style="color: #808080;">//create a new variable for the array counter</span></span>
<span style="color: #000099;"><span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">1</span>;</span>
<span style="color: #000099;"><span style="color: #808080;">//loop y, decrement the variable y</span></span>
<span style="color: #000099;"><span style="color: #0000ff;">for</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff">y</span><span style="color: #0000ff;">=</span><span style="color: #ff0000;">5</span>; <span style="color: #0000ff">y</span> <span style="color: #800000;">&gt;</span> <span style="color: #ff0000;">0</span>; y<span style="color: #0000ff;">--</span><span style="color: #000000;">&#41;</span></span>
<span style="color: #000099;"><span style="color: #000000;">&#123;</span></span>
<span style="color: #000099;">	arrTemp<span style="color: #000000;">&#91;</span><span style="color: #0000ff">x</span><span style="color: #0000ff;">++</span><span style="color: #000000;">&#93;</span> <span style="color: #0000ff">=</span> <span style="color: #0000ff">y</span>;</span>
<span style="color: #000099;"><span style="color: #000000;">&#125;</span></span>
<span style="color: #000099;"><span style="color: #800000;">&lt;/cfscript&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #800000;">&lt;cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#arrTemp#&quot;</span> <span style="color: #0000ff;">label</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Combined Increment Decrement Operator Test&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>The above code loops from 5 to 1, decrementing the value of <code>y</code> by 1 on each iteration. At the same time, the value of <code>x</code> increments by 1 on each iteration and is used to define the array index, i.e. <code>arrTemp[1]</code>.</p>
<p>The returned output can be displayed as follows:</p>
<p><img src='http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/02/combined-operator-test.png' alt='Combined Increment Decrement Operator Test' /></p>
<p>Such code serves to demonstrate how you can set up complex operations without the need to use the following, antiquated operations:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #800080;">incrementValue</span><span style="color: #000000;">&#40;</span><span style="color: #0000ff">x</span><span style="color: #000000;">&#41;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">y</span> <span style="color: #0000ff">=</span> <span style="color: #0000ff">y</span><span style="color: #0000ff;">+</span><span style="color: #ff0000;">1</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> a <span style="color: #0000ff">=</span> <span style="color: #800080;">decrementValue</span><span style="color: #000000;">&#40;</span>a<span style="color: #000000;">&#41;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> b <span style="color: #0000ff">=</span> b<span style="color: #0000ff;">-</span><span style="color: #ff0000;">1</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p><strong>- (Unary Negation)</strong></p>
<p>The unary negation operator precedes its operand and negates it. For example, y = -x negates the value of x and assigns that to y; that is, if x were 3, y would get the value -3 and x would retain the value 3. This is not new to ColdFusion 8, but it is worth a mention.</p>
<p>In ColdFusion, this can be shown by the following:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">x</span> <span style="color: #0000ff">=</span> <span style="color: #ff0000;">3</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #800000;">&lt;cfset</span> <span style="color: #0000ff">y</span> <span style="color: #0000ff">=</span> <span style="color: #0000ff;">-</span><span style="color: #0000ff">x</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #800000;">&lt;cfdump</span> <span style="color: #0000ff;">var</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;#variables#&quot;</span> <span style="color: #0000ff;">label</span><span style="color: #0000ff;">=</span><span style="color: #009900;">&quot;Unary Operator Test&quot;</span> <span style="color: #0000ff;">/</span><span style="color: #800000;">&gt;</span></span></pre></div></div>

<p>The above code returns:</p>
<p><img src='http://www.simonwhatley.co.uk/blog/wp-content/uploads/2008/02/unary-operator-test.png' alt='Unary Operator Test' /></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-6475233631580417";
/* 468x60 Basic */
google_ad_slot = "7117418273";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.simonwhatley.co.uk/using-javascript-arithmetic-operators-in-coldfusion-8/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

