Learn
Functions
Parameters and Arguments
Parameters are placeholders or variables defined within a function's declaration. They act as a mechanism to pass data into a function. Think of parameters as empty slots that can be filled with actual values when the function is called.
In the above example, name
is a parameter defined within the function greet()
. It represents the value that will be passed into the function when it is called.
What are Arguments?
Arguments are the actual values that are passed into a function when it is called. They correspond to the parameters defined in the function's declaration. Arguments are assigned to the parameters in the order they are passed.
In the above example, "John"
is an argument that is passed into the greet()
function. It fills the name
parameter within the function, resulting in the output "Hello, John!".
Importance of Parameters and Arguments
Using parameters and arguments allows us to create functions that can perform calculations or actions on different values without hardcoding specific values into the function. This makes our code more reusable and adaptable as we can pass different values to the same function, achieving different results.
Instructions
Modify the greet
function to take two parameters: name
and age
.
Inside the greet
function, modify the console.log to print the message:
Note: Replace [name]
and [age]
with the actual parameters.
Sign up to start coding
Already have an account?
Sign In