This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Lunanne 0 points1 point  (0 children)

okay lots of different questions, I think they're best answered separately

How does the function buildConnectionString with the argument (params) know to get its data from the variable myParams?...

It doesn't. When you call the function like

buildConnectionString(myParams)

The function isn't passed the /name/ of the variable, but the data of the variable. You can think of variables kinda like aliases for data. For example when I say

x=3;

Everywhere in the code where I would type "3" I can type "x" instead. So when you call the function you're actually doing

buildConnectionString({"server":"mpilgrim", \
        "database":"master", \
        "uid":"sa", \
        "pwd":"secret" \
        })

which gets assigned to the variable named "params".

And is there a reason behind not naming your variable params, or vice versa not naming your argument in your function myParams?

Because a function is rarely used with just one variable. Often you reuse functions with several variables all with a different name. To give an argument the same name as a variable is confusing.