In this JavaScript video tutorial I spend some time explaining the complexity of using Arrays and Functions in JavaScript. If you missed part 1, watch that first JavaScript Video Tutorial.
JavaScript Arrays are different from many languages because you can pretty much throw anything in them. This is because JavaScript isn’t strongly typed once again.
JavaScript Functions are also odd because they don’t follow the normal scoping rules used in most other languages. And, did you know you can completely disregard the number of arguments a function will accept? You’ll learn this plus how to:
- Manipulate Array Data
- Use Multi-Dimensional Arrays
- Use the For In Loop
- Do Awesome Things with the Argument Object
And, much, much more! Like always the code follows the video. If you have any questions, leave them below.
Code From the Video
Thanks for nice tutorial 🙂
You’re very welcome. Thanks for stopping by
function addMany(a,b,c,d,e,f) ???
I really am enjoying your tutorials and am grateful for such an easy way to get up to speed with JavaScript, XML, css, etc.
On this tutorial about functions, I am glad to learn about this but have one question. I assume that this trick is limited to the number of arguments included in the functioln declaration and more that more arguments (7 or more in our example) could not be passed without a problem. Is this correct?
Thanks,
Jerry
I was a bit premature. You covered it immediately after I stopped to ask the question. Sorry and Thanks for your perception of anticipating the question.
Jerry
No problem. I try to cover everything in the tutorial series. It takes some time to learn how to program. I’m glad you find the videos useful 🙂
Great tutorials,Thank you for the effort
Confused with part of the code
In addMany() function ,why the sum is not 0 before the loop
Thanks
Derek made a mistake because he was super fast at demoing.
Just set var i = 0; and var sum=0;
See function below.
function addMany(a,b,c,d,e,f)
{
var i=0;
var sum=0;
document.write(“Arguments Length: ” + arguments.length + “”);
while(i < arguments.length)
{
sum = sum + arguments[i];
i++;
}
document.write("Sum of arguments: " + sum + "”);
}
I’m sorry if I made a mistake. I’ll take a look. Thank you for pointing that out
nction addFunction(a,b)
{
return a+b;
}
+
=
whats wrong with the functionfu
what happened no function sent
Sorry I didn’t get it. You can put code between code tags and then I can see it. Sorry about that.
(function addFunction()
{var a=document.getElementById(‘hi’).value;
var b=document.getElementById(‘hii’).value;
function c(a,b){
return a+b;}
}
+
=)