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
godzsa
2,4556 gold badges39 silver badges61 bronze badges
2 Answers 2
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
cocco
16.8k7 gold badges65 silver badges77 bronze badges
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
serakfalcon
3,5311 gold badge26 silver badges35 bronze badges
1 Comment
godzsa
no this is not a homework... I'm trying to write scripts for fun
lang-js