Code Highlights logo

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.

1function greet(name) {
2 console.log(`Hello, ${name}!`);
3}

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.

1greet("John");

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

1.

Modify the greet function to take two parameters: name and age.

2.

Inside the greet function, modify the console.log to print the message:

1"Hello, [name]! You are [age] years old."

Note: Replace [name] and [age] with the actual parameters.

Sign up to start coding

Already have an account?

Sign In

Course content