javascript-functions Flashcards
What is a function in JavaScript?
Functions allow you to package up code for use later in your program; collection of code we can call any time we like and pass in values
Describe the parts of a function definition.
- Function keyword
- Optional name
- Comma separated list of zero or more arguments surrounded by parentheses
- Code block
- Optional return statement
Describe the parts of a function call.
- Function name
2. Comma separated list of zero or more arguments surrounded by parentheses
When comparing them side-by-side, what are the differences between a function call and a function definition?
Definition has the function keyword and code block (as seen by the curly braces)
What is the difference between a parameter and an argument?
When we define a function, we declare parameters (like a placeholder) and when we call a function, we pass it arguments (actual values)
Why are function parameters useful?
They work as placeholders for values that are not known until it can later be used to pass in any value into a function
What two effects does a return statement have on the behavior of a function?
- Causes the function to produce a value we can use in our program. 2. Prevents any more code in the function’s code block from being run.