Chaining ColdFusion Assignment Operators

Posted: September 13, 2011 in ColdFusion

Thanks to Mike Henke, I found out you can chain assignment operators (“=”) in ColdFusion.

An example of this would be:

var1 = var2 = var3 = 123;

Resulting in:

var1 = 123
var2 = 123
var3 = 123

Behind the scenes it’s interpreted such as var1 = (var2 = (var3 = 123));
(It is right-associative, being the last assignment operation is evaluated first and propagated leftward. Also, don’t try that interpreted code in CF because it will fail.)

While not a major find in programming history, this little flick of keystrokes can save you some repetitive typing should you ever need to set multiple variables to the same value.

Advertisements
Comments

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s