It's actually not an optimization at all. JavaScript moves all variable declarations to the top of their function scope. For example:

```javascript
function foo() {
	bar();
	var x = 1;
}
```

is interpreted as

```javascript
function foo() {
	var x;
	bar();
	x = 1;
}
```

In this situation, doing:

```javascript
function blah() {
    for (var i = 0; i < sources.length; i++) {
        var source = document.createElement('source');
        source.src = sources[i].src;
        source.type = sources[i].type;
        video.appendChild(source);
    }
}
```

is equivalent to

```javascript
function blah() {
    for (var i = 0; i < sources.length; i++) {
        var source = document.createElement('source');
        source.src = sources[i].src;
        source.type = sources[i].type;
        video.appendChild(source);
    }
}
```

in terms of execution. The latter is more readable, though, so we usually prefer it.