Search⌘ K

Function Arguments

Explore how JavaScript functions take arguments to become dynamic and flexible. Learn to define functions with single or multiple parameters, handle undefined arguments, and understand local variable scope inside functions for better coding practices.

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.

Node.js
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 ...