How are arguments passed
Let's say you define a function as follows
function Foo(argument1, argument2, argument3) {
return argument1 + argument2
}
When the function is called, the arguments get assigned respectively as passed, substituting undefined for any that are missing. For illustration purposes, you can imagine it as the following code (although it doesn't really happen anywhere and any expressions you have will be evaluated in the calling scope).
// somewhere in the script
foo('bar', 'baz' + '1')
...
// in scope of function Foo, between its { and }
var argument1 = 'bar', // these lines never actually exist
argument2 = 'baz1', // but variables are created as if they were
argument3 = undefined
return argument1 + argument2
How the script engine actually handles this situation is an implementation detail and you needn't worry about it.
Also, it doesn't matter at all whether you use a literal string or pass a variable that has a string.
var a = 'like this', b = 'and this'
foo('like this', 'and this')
foo(a, b) // the function has no way to differentiate these 2 lines
As a side note, this is perfectly safe, because strings are immutable. Assigning to them inside the function will not propagate back to the outer scope (even if they are String objects). With JavaScript passing a string is actually the same as passing an integer.
Why would you use a string as an argument
There are several cases where this design decision would make sense. In the case of addEventListener it is useful because you can easily make your own events that you can be sure won't trip over some browser's internal mechanism.
Should the argument names match
Absolutely not. What's inside the function argument list is completely isolated of any interaction with other code, but when you're maintaining a code base you want your code to be readable and consistent. This is matter of agreement, not something enforced by the language.
addEventListener()works, what the first argument means or how AngularJS' dependeny injection (resolution of the argument name$scopeto inject the proper reference) works?addEventListener()is given as an example and AngularJS is mentioned to contrast how it uses strings to preserve argument names.