The difference between the two examples you've posted is essentially one is storing a variable (var second) within a function and one is not (var first).
In your second example you are assigning the element object to a variable inside an anonymous, self-invoking function (no name is attributed to it so it's value is never stored, and the following parenthesis attached at the end call that function).
An example of a named variable is...
function yourFunctionName () {
console.log("I'm a function with a name");
}
An anonymous function is a function without a name, even though it's assigned to the variable anon_function its' still anonymous...
var anon_function = function(){
console.log("I'm anonymous");
}
The return value of the above function is stored in the anon_function variable.
The trailing parenthesis tell the function to execute straight away as if you were calling a named function.
function(){
console.log("I'm anonymous and self-invoking");
}()
Once the function is run and then terminates, variables created inside the function are discarded and the global object remains as it was.
The parenthesis that wrap the entire function are 'recommended' to help programmers distinguish from normal functions:
(function(){
console.log("I'm anonymous, self-invoking and wrapped in parenthesis just for clarity");
})()
There is a short pdf article about self-invoking functions here and a good article on anonymous functions here
secondis not polluting the global scope.