Chaining ColdFusion Assignment Operators

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