coldfusion - What are the pros and cons to explicitly scoping a variable inside a function? -


i read in cf should scope variables because if don't provide explicit scope cf have search through scopes until finds variable. case? if so, test2() more efficient way of writing function?

<cfscript>     function test() {         var result = 5;         result = 42;         return result;       }      function test2() {         var result = 5;         local.result = 42;         return local.result;         } </cfscript> 

with the introduction of local scope, using var keyword tells cf vared stuff belongs in local scope. both examples accomplish same thing.

i recommend against mixing two.


Comments