Question: I always try to make use of the var keyword when inside functions using CF, but one probably stupid question I have is, how often do you have to use it ?

Example : 

```
<cfset var local = ""> <!-- set at the top of the function -->

<!-- then later in the function -->
<cfset var local.firstname = "steve">
<cfset var local.lastname = "smith">
<cfset var local.email = "email@email.com">

```

is it a case of every time you write a variable you have to set the keyword, or just the first instance of it when used within a function ?

Or is it just the same as

```
<cfset var local = ""> <!-- set at the top of the function -->

<!-- then later in the function -->
<cfset local.firstname = "steve">
<cfset local.lastname = "smith">
<cfset local.email = "email@email.com">

```

Answer: 
Which version of ColdFusion are you using? Since ColdFusion 9 `local` is a scope, so there's no point in specifically creating it.

To answer your question: all function-local variables need to be actively made local to the function. ColdFusion does not do this automatically.

There's two ways of doing this. Via the `var` keyword:

```
var someVar = someValue;

```

Or via the `local` scope:

```
local.someVar = someValue;

```

You are confused in your examples as to what a variable is. Given this code:

```
var myStruct = {};
myStruct.someKey = "some value";

```

In this examply `myStruct` is the variable. `myStruct.someKey` is not a discrete variable, it's merely a subkey of the `myStruct` variable. So this doesn't make sense:

```
var myStruct = {};
var myStruct.someKey = "some value";

```
If you are not using the local scope, you only have to use the keyword `var` once per variable.

I was introduced to User Defined Functions with version 7.1. I'm not sure about other versions, but in that one, you had to `var` all your variables right after the `cfargument` tags, before any other commands were executed. In other words, this was ok.

```
<cffunction etc>
<cfargument name = "arg1">
<cfset var x = 0>
<cfquery>
sql goes here
</cfquery>
<cfset x = 3>

```

but this would throw an error:

```
<cffunction etc>
<cfargument name = "arg1">

<cfquery>
sql goes here
</cfquery>
<cfset var x = 3>

```