godzsa
godzsa

Reputation: 2395

What is the difference between these function callings?

So I was wondering what is the difference between these:

var a=5;
var b=3;

function asd(a,b) {
   a=a+b;
   b=b-a;
}

function asd2(){
   a=a+b;
   b=b-a;
}

function asd3(var a, var b){
   a=a+b;
   b=b-a;
}

Sorry for the lame question, but didn't know how to google is :S.

Upvotes: 0

Views: 83

Answers (2)

serakfalcon
serakfalcon

Reputation: 3531

I hope this isn't a homework question, but I'll point you in the right direction.

What is the output of:

asd(123,456);

Can you change the output of

asd2();

if so, how?

to tell the difference between asd() and asd3() try this:

var c=10;
var d=4;
alert (asd(c,d));
alert ("c is " + c + " and d is " + d);

versus

var c=10;
var d=4;
alert(asd3(c,d));
alert ("c is " + c + " and d is " + d);

Upvotes: 0

cocco
cocco

Reputation: 16716

the first takes the parameters from the function arguments,

the second takes the global defined vars.

the third should not work.

Upvotes: 5

Related Questions