Insofar as there are more bytes to download, the first example is slower.
However, I'm certain that you will never be able to differentiate between the negligible micro-optimization of the latter example and the former example. Other than organization, there's no reason to bother.
That said, for the sake of organization, I would definitely bother! Keeping your code organized will speed development time. Keeping all of your JavaScript in one place will prevent you from running around searching for a snippet.
I would strive to move as much code first into an external file, and anything else into the foot of your document.
- You will garner the most speed benefit by using an external file (due to browser caching) than anything else.
- You will allow your markup to be rendered by the browser before downloading or executing your JavaScript if you move the
<script> tags to the footer of the page. This will create the illusion of a faster download.
Incidentally, (and just as trivially) the most optimized version of your script (aside from using an external file) would be:
<script>
var x='foo', y='bar';
</script>