What is the difference between:
function sumar() {
var suma = 0;
var f = 0;
for ( f; f < arguments.length; f++) {
suma = suma + arguments[f];
}
document.write(suma);
}
sumar(2,3,4);
with this:
function sumar() {
var suma = 0;
var f = 0;
for ( f; f < arguments.length; f++) {
suma = suma + arguments[f];
}
return suma;
}
document.write(sumar(2,3,4));
In the first function:
The second:
It always returns the result with which:
document.write(sumar(2,3,4));
var resultado = sumar(1,2,3) //resultado=6
If you have to choose one, I would choose the second one that gives you more game. But it all depends on what you are looking for with it.