Karolina Ticha Karolina Ticha - 1 year ago 89
Javascript Question

Purpose of JavaScript function parameter

I can't understand the purpose of parameters in JavaScript functions. Let's say:

function sayWelcome(name) {
document.write("Welcome to our page " + name);

What thing should do that name on first line? Why I should use that?

Answer Source

Lets say you've got an automatic teller machine (atm). The atm wants to know who you are and what you want to return your money. So the atm function would look like

function atm(name, pin, money){
   if(all true){
      return money;

And the user would do:

atm("john doe", 1234, 1000);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download