<?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; comparison</title>
	<atom:link href="http://www.simonwhatley.co.uk/tag/comparison/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>
	</channel>
</rss>

