0

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.

asked Dec 27, 2013 at 14:36

2 Answers 2

5

the first takes the parameters from the function arguments,

the second takes the global defined vars.

the third should not work.

answered Dec 27, 2013 at 14:38
Sign up to request clarification or add additional context in comments.

3 Comments

but how does the first affect the a,b variables?
it simply does not consider the global variables.
if you call the first function without parameters you get 2 undefined values
0

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);
answered Dec 27, 2013 at 14:47

1 Comment

no this is not a homework... I'm trying to write scripts for fun

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.