The difference between the two depends on how you intend to use the Javascript function.
When declaring your variables inside the function, like example #2 above, the variable will always hold one particular value. For example,
function function_name()
{
var1 = 1;
some code;
}
When that variable is inside the function, it will always hold the value of 1 (unless you make changes to the value later in the function).
In example #1, the way the javascript is written allows you to give different values to the variables depending on how you call the function. For example,
function function_name(var1)
{
some code
}
you could call that function, using different values for the variable each time:
function_name(2);
function_name(455);
In line #1, the "var1" variable would equal 2, and in line 2, it would equal 455.