Function Arguments
We'll add on to functions by describing function arguments. These make functions considerably more powerful, as they allow us to pass information into a function. The code inside functions becomes dynamic.
We'll cover the following...
Arguments
Functions have more stuff built into them that makes them extremely powerful. They don’t just do the same exact thing every time. They’re dynamic.
We can write a function in a way that makes it dynamic. We can give the function a value to use when we call it. The function will then use this value when it runs its code.
Have a look at this code and we’ll discuss it afterward.
function printValue(someValue) {console.log('The item I was given is: ' + someValue);}printValue('abc'); // -> The item I was given is: abc
We have a function named printValue
. Inside the parentheses on line 1, we put a word: someValue
. This word symbolizes a future value. It’s a variable that we can use inside the function.
someValue
is a placeholder variable. It will be different every time the function is called, depending on how we call it.
This variable gets a value ...