Well, you can have external. This is javascript you load through an extrnal file
<Script type="text/javascript" src="path/to/javascript.js"></script>
Then you have embedded
<script type="text/javascript">
function foo() {
alert('bar');
}
foo();
</script>
Then you have inline. Imho(imho = In my humble opinion) inline comes in two varieties. inline functions or onclick handlers like you have shown.
The greater consensus is however that inline functions are where HTML code mixes with javascript like the example below.
<input type="button" onclick="foo()">
or an inline function as I and a few other developpers see it. Please note, this is my interpretation of the meaning inline. That interpretation is: A variable to which you assign a function.
Please note, this is an interpretation, but the meaning inline is very
vague, but not specified somewhere. When you are used to programming
higher level programming languages like java or c, inline has a whole
different meaning and meanings can blur over from one language to
another. That is why I think this is also an inline function because
you can use it within a function do define a scoped function in a
closure, or assign it to onlcick handlers of a DOM element, etc...
var foo = function() {
alert('bar');
}
foo();
To answer your second question:
Don't use inline. It's valid to use, but it means copying over all the javascript between separate html files.
If you make it abstract so you access all identifiers by id, and use the javascript representations it will run a lot smoother, and will be easier to maintain.
document.getElementById('someobjectname')
gives you the object you want from within a js file.
If you attach some onload handlers to the document
element you can fire up your javascript when the document has finished loading into the browser and then perform your magic on it.