Functions are incredibly useful and can be made to do a great many things. Taking and argument is one of those things.

In the previous example we had a function that took 3 and added it to 6. This is a very useful in the off chance you specifically want to know that particular answer. However in most cases you would want to find out about 2 different numbers, not just 3 + 6.

That’s where arguments come in handy, they are a simple way to provide your function with data it needs. You just add the arguments in the “Parentheses ( )” of the function and you can now use them inside your function. Let see an example.

//function that takes 2 arguments
function Add_Two_Numbers(a, b){
    return a + b;

The above function will take 2 numbers as arguments and return the sum. We will use 4 as a and 8 as b.

//function that takes 2 arguments
function Add_Two_Numbers(a, b){
    return a + b


//This will return 12;

This is a very basic example, however you can create extremely complicated functions.

Arguments aren’t limited to numbers, you can pass it strings, or even arrays. With this you can create a function that can take in an array and use a “loop” to have it do an action on each item in the array.

This is a good example of how you can start using all these basic building blocks and using them together to build something beautiful.

Congratulations! You have leveled up in programming!

Next Introduction to JavaScript

Previous Demystifying Programming – 6 Functions

Leave a Reply

Your email address will not be published. Required fields are marked *