What is a function in JavaScript?
In JavaScript, a function is a block of code that is defined once and can be called any number of times to perform a specific task.
Describe the parts of a function definition.
1 The function keyword: This is the keyword that indicates that the code following it is a function definition.
2 The function name: This is the name of the function, which is used to identify the function and call it later on.
3 The parameter list: This is a list of one or more parameters that the function can take as input. Each parameter is a variable that will be assigned the value of the argument passed to the function when it is called.
4 The function body: This is the code that is executed when the function is called. It is contained within a pair of curly braces {} and may include any number of JavaScript statements, such as variable declarations, loops, conditional statements, and more.
Describe the parts of a function call.
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function definition is a block of code that defines a function and specifies what it does. A function call is an expression that invokes a function and passes one or more arguments to it. Here are the main differences between a function call and a function definition in JavaScript:
What is the difference between a parameter and an argument?
a parameter is a variable that is declared in the function definition, and it is used to receive the value of the argument passed to the function when it is called. An argument is a value that is passed to a function when it is called, and it is assigned to the corresponding parameter in the function definition. In other words, a parameter is a placeholder for an argument that is passed to a function.
Why are function parameters useful?
they allow a function to take one or more inputs, which can then be used within the function body to perform a specific task. Allows us to re-run the function with new values.
What two effects does a return statement have on the behavior of a function?