Reputation: 19
I am kind of struggling the question and what to do here so I wish to seek help to solve this:
So I know empty Array is:
const emptyArray = []
Function with 1 argument would be:
function oneArgument(argument) {}
"Inside the function, add the argument to the array." is what I seem to struggle with, what does the task mean?
and at the end I guess I will just give value to oneArgument(someValue)
Would apprechiate the help :)
Upvotes: 0
Views: 461
Reputation: 176
We create an empty array, so that we could store values. What happens next is we make a function, that takes in a single argument number
. We add it to our array and call the function.
We use arguments for functions. This allows us to have reusable functions. We might use the same function all over our application passing different type of number. Maybe in one file we might pass number 500
, maybe in another file we need a negative number. Whole idea behind this, is that we make it resuable. The function doesnt care what type of number we pass, it will act the same way every time we call it, but with different number or any other value. Argument means that, function expects a value and this value can differ every single time we call the function.
Hope this helps.
const numbers = [];
function updateNumbersList (number) {
numbers.push(number)
}
updateNumbersList(1)
console.log(numbers)
Upvotes: 2